diff options
| author | Pietro Gagliardi <[email protected]> | 2014-12-07 16:22:51 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-12-07 16:22:51 -0500 |
| commit | e224950cf48abe0a0d439fb8d4f154fe59984de7 (patch) | |
| tree | a910737ad2adac740186fd07262b82aee82e1c78 /wintable/new/util.h | |
| parent | 75c9f738703a355dddb13b0a0c8df9a446550ba1 (diff) | |
Some allocator cleanup in the new Table.
Diffstat (limited to 'wintable/new/util.h')
| -rw-r--r-- | wintable/new/util.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/wintable/new/util.h b/wintable/new/util.h index 2bcfd94..dc51605 100644 --- a/wintable/new/util.h +++ b/wintable/new/util.h @@ -12,3 +12,37 @@ static BOOL runHandlers(const handlerfunc list[], struct table *t, UINT uMsg, WP return TRUE; return FALSE; } + +// memory allocation stuff +// each of these functions do an implicit ZeroMemory() +// we're using LocalAlloc() because: +// - whether the malloc() family supports the last-error code is undefined +// - the HeapAlloc() family DOES NOT support the last-error code; you're supposed to use Windows exceptions, and I can't find a clean way to do this with MinGW-w64 that doesn't rely on inline assembly or external libraries (unless they added __try/__except blocks) +// - there's no VirtualReAlloc() to complement VirtualAlloc() and I'm not sure if we can even get the original allocated size back out reliably to write it ourselves (http://blogs.msdn.com/b/oldnewthing/archive/2012/03/16/10283988.aspx) +// needless to say, TODO + +static void *tableAlloc(size_t size, const char *panicMessage) +{ + HLOCAL out; + + out = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, size); + if (out == NULL) + panic(panicMessage); + return (void *) out; +} + +static void *tableRealloc(void *p, size_t size, const char *panicMessage) +{ + HLOCAL out; + + out = LocalReAlloc((HLOCAL) p, size, LMEM_ZEROINIT); + if (out == NULL) + panic(panicMessage); + return (void *) out; +} + +static void tableFree(void *p, const char *panicMessage) +{ + if (LocalFree((HLOCAL) p) != NULL) + panic(panicMessage); +} |
