mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
Fix memory allocation on Windows.
* Take the cache line roundings into account when allocating a hunk. * Use size_t were apropriate. * remove some unnecessary and likely broken calls. Another case of: "How could this ever work"?
This commit is contained in:
parent
60c12228c9
commit
b9e5306c84
1 changed files with 8 additions and 11 deletions
|
@ -30,17 +30,18 @@
|
|||
|
||||
byte *membase;
|
||||
int hunkcount;
|
||||
int hunkmaxsize;
|
||||
int cursize;
|
||||
size_t hunkmaxsize;
|
||||
size_t cursize;
|
||||
|
||||
void *
|
||||
Hunk_Begin(int maxsize)
|
||||
{
|
||||
/* reserve a huge chunk of memory,
|
||||
but don't commit any yet */
|
||||
/* reserve a huge chunk of memory, but don't commit any yet */
|
||||
/* plus 32 bytes for cacheline */
|
||||
hunkmaxsize = maxsize + sizeof(size_t) + 32;
|
||||
cursize = 0;
|
||||
hunkmaxsize = maxsize;
|
||||
membase = VirtualAlloc(NULL, maxsize, MEM_RESERVE, PAGE_NOACCESS);
|
||||
|
||||
membase = VirtualAlloc(NULL, hunkmaxsize, MEM_RESERVE, PAGE_NOACCESS);
|
||||
|
||||
if (!membase)
|
||||
{
|
||||
|
@ -63,10 +64,7 @@ Hunk_Alloc(int size)
|
|||
|
||||
if (!buf)
|
||||
{
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&buf, 0, NULL);
|
||||
Sys_Error("VirtualAlloc commit failed.\n%s", buf);
|
||||
Sys_Error("VirtualAlloc commit failed.\n");
|
||||
}
|
||||
|
||||
cursize += size;
|
||||
|
@ -97,4 +95,3 @@ Hunk_Free(void *base)
|
|||
|
||||
hunkcount--;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue