Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 24428

re: If you're going to write your own allocator, you need to respect the MEMORY_ALLOCATION_ALIGNMENT

$
0
0

@Rodrigo -- here is my quick approach:

struct EXTRASTUFF

{

   DWORD Awesome1;

   DWORD Awesome2;

};

static_assert(sizeof(EXTRASTUFF) <= MEMORY_ALLOCATION_ALIGNMENT)

// error checking elided for expository purposes

void *operator new(size_t n)

{

 EXTRASTUFF *extra = (EXTRASTUFF)malloc(MEMORY_ALLOCATION_ALIGNMENT + n);

 extra->Awesome1 = get_awesome_1();

 extra->Awesome2 = get_awesome_2();

 return ((BYTE *)extra) + MEMORY_ALLOCATION_ALIGNMENT;

}

But there are probably better ones


Viewing all articles
Browse latest Browse all 24428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>