1. A computer-implemented method of allocating memory to a program during execution, the method comprising: allocating a first buffer within a first memory that is accessible to a plurality threads when executing on a coprocessor; during execution of a processing task on the coprocessor; notifying a worker thread executing on a central processing unit that the first buffer is full; allocating a first portion of a swap buffer within a second memory that is not accessible to the plurality of threads during execution; and swapping the first buffer into the first portion of the swap buffer.