Switched to the Windows API heap functions in windows/alloc.c.
This commit is contained in:
parent
a0e2c3cf94
commit
a70d56d77c
|
@ -7,16 +7,23 @@
|
|||
// passing NULL to tableRealloc() acts like tableAlloc()
|
||||
// passing NULL to tableFree() is a no-op
|
||||
|
||||
static HANDLE heap;
|
||||
|
||||
BOOL initAlloc(void)
|
||||
{
|
||||
heap = HeapCreate(0, 0, 0);
|
||||
return heap != NULL;
|
||||
}
|
||||
|
||||
void *uiAlloc(size_t size, const char *type)
|
||||
{
|
||||
void *out;
|
||||
|
||||
out = malloc(size);
|
||||
out = HeapAlloc(heap, HEAP_ZERO_MEMORY, size);
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type);
|
||||
abort();
|
||||
}
|
||||
ZeroMemory(out, size);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -26,12 +33,11 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
|||
|
||||
if (p == NULL)
|
||||
return uiAlloc(size, type);
|
||||
out = realloc(p, size);
|
||||
out = HeapReAlloc(heap, HEAP_ZERO_MEMORY, p, size);
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type);
|
||||
abort();
|
||||
}
|
||||
// TODO zero the extra memory
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -39,5 +45,6 @@ void uiFree(void *p)
|
|||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
free(p);
|
||||
if (HeapFree(heap, 0, p) == 0)
|
||||
logLastError("error freeing memory in uiFree()");
|
||||
}
|
||||
|
|
|
@ -64,6 +64,9 @@ const char *uiInit(uiInitOptions *o)
|
|||
|
||||
options = *o;
|
||||
|
||||
if (initAlloc() == 0)
|
||||
return loadLastError("error initializing memory allocations");
|
||||
|
||||
nCmdShow = SW_SHOWDEFAULT;
|
||||
GetStartupInfoW(&si);
|
||||
if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
|
||||
|
|
|
@ -75,3 +75,6 @@ extern HMENU makeMenubar(void);
|
|||
extern const uiMenuItem *menuIDToItem(UINT_PTR);
|
||||
extern void runMenuEvent(WORD, uiWindow *);
|
||||
extern void freeMenubar(HMENU);
|
||||
|
||||
// alloc.c
|
||||
extern BOOL initAlloc(void);
|
||||
|
|
Loading…
Reference in New Issue