Difference between revisions of "Notes:Fake stack"
From Maths
(Created page with "Grab some memory with: <code>char* data = malloc(2*1024*1024*1024); //2gb</code> When you're asked for data do something like this: <source lang="cpp"> void* allocOnStack(u...") |
(No difference)
|
Revision as of 15:20, 28 September 2015
Grab some memory with:
char* data = malloc(2*1024*1024*1024); //2gb
When you're asked for data do something like this:
void* allocOnStack(uint64 size) { void* result = (void*) data; data += size; uint64* sizeNote = (uint64*) data; *sizeNote = size; data += sizeof(uint64); return result; }
and for de-allocating
void* stackFree(void* ptr) { uint64 size = *(((uint64*)data)-1) if((void*) (data-size-sizeof(uint64)) == ptr) { //okay data = data-size-sizeof(uint64); //or just data=ptr; } else { //exit with critical memory error! } }