mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-30 00:10:53 +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;
|
byte *membase;
|
||||||
int hunkcount;
|
int hunkcount;
|
||||||
int hunkmaxsize;
|
size_t hunkmaxsize;
|
||||||
int cursize;
|
size_t cursize;
|
||||||
|
|
||||||
void *
|
void *
|
||||||
Hunk_Begin(int maxsize)
|
Hunk_Begin(int maxsize)
|
||||||
{
|
{
|
||||||
/* reserve a huge chunk of memory,
|
/* reserve a huge chunk of memory, but don't commit any yet */
|
||||||
but don't commit any yet */
|
/* plus 32 bytes for cacheline */
|
||||||
|
hunkmaxsize = maxsize + sizeof(size_t) + 32;
|
||||||
cursize = 0;
|
cursize = 0;
|
||||||
hunkmaxsize = maxsize;
|
|
||||||
membase = VirtualAlloc(NULL, maxsize, MEM_RESERVE, PAGE_NOACCESS);
|
membase = VirtualAlloc(NULL, hunkmaxsize, MEM_RESERVE, PAGE_NOACCESS);
|
||||||
|
|
||||||
if (!membase)
|
if (!membase)
|
||||||
{
|
{
|
||||||
|
@ -63,10 +64,7 @@ Hunk_Alloc(int size)
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
Sys_Error("VirtualAlloc commit failed.\n");
|
||||||
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(LPTSTR)&buf, 0, NULL);
|
|
||||||
Sys_Error("VirtualAlloc commit failed.\n%s", buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cursize += size;
|
cursize += size;
|
||||||
|
@ -97,4 +95,3 @@ Hunk_Free(void *base)
|
||||||
|
|
||||||
hunkcount--;
|
hunkcount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue