Get rid of MemAlloc/MemFree.

After commit 521473ee there's no point in keeping these around.
Instead, use the same heap in containers as the C++ standard library.
pull/598/head^2
whitequark 2020-05-10 06:11:53 +00:00
parent 521473ee4b
commit 9c1804b1b5
5 changed files with 13 additions and 40 deletions

View File

@ -215,12 +215,12 @@ public:
void ReserveMore(int howMuch) {
if(n + howMuch > elemsAllocated) {
elemsAllocated = n + howMuch;
T *newElem = (T *)MemAlloc((size_t)elemsAllocated*sizeof(T));
T *newElem = (T *)::operator new[]((size_t)elemsAllocated*sizeof(T));
for(int i = 0; i < n; i++) {
new(&newElem[i]) T(std::move(elem[i]));
elem[i].~T();
}
MemFree(elem);
::operator delete[](elem);
elem = newElem;
}
}
@ -286,7 +286,7 @@ public:
void Clear() {
for(int i = 0; i < n; i++)
elem[i].~T();
if(elem) MemFree(elem);
if(elem) ::operator delete[](elem);
elem = NULL;
n = elemsAllocated = 0;
}
@ -401,12 +401,12 @@ public:
void ReserveMore(int howMuch) {
if(n + howMuch > elemsAllocated) {
elemsAllocated = n + howMuch;
T *newElem = (T *)MemAlloc((size_t)elemsAllocated*sizeof(T));
T *newElem = (T *)::operator new[]((size_t)elemsAllocated*sizeof(T));
for(int i = 0; i < n; i++) {
new(&newElem[i]) T(std::move(elem[i]));
elem[i].~T();
}
MemFree(elem);
::operator delete[](elem);
elem = newElem;
}
}
@ -525,7 +525,7 @@ public:
void DeepCopyInto(IdList<T,H> *l) {
l->Clear();
l->elem = (T *)MemAlloc(elemsAllocated * sizeof(elem[0]));
l->elem = (T *)::operator new[](elemsAllocated * sizeof(elem[0]));
for(int i = 0; i < n; i++)
new(&l->elem[i]) T(elem[i]);
l->elemsAllocated = elemsAllocated;
@ -537,7 +537,7 @@ public:
elem[i].Clear();
elem[i].~T();
}
if(elem) MemFree(elem);
if(elem) ::operator delete[](elem);
elem = NULL;
elemsAllocated = n = 0;
}

View File

@ -110,11 +110,11 @@ void SMesh::Simplify(int start) {
STriMeta meta = l[start].meta;
STriangle *tout = (STriangle *)MemAlloc(maxTriangles*sizeof(*tout));
STriangle *tout = new STriangle[maxTriangles];
int toutc = 0;
Vector n = Vector::From(0, 0, 0);
Vector *conv = (Vector *)MemAlloc(maxTriangles*3*sizeof(*conv));
Vector *conv = new Vector[maxTriangles * 3];
int convc = 0;
int start0 = start;
@ -234,8 +234,8 @@ void SMesh::Simplify(int start) {
for(i = 0; i < toutc; i++) {
AddTriangle(&(tout[i]));
}
MemFree(tout);
MemFree(conv);
delete[] tout;
delete[] conv;
}
void SMesh::AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3) {

View File

@ -1,8 +1,5 @@
//-----------------------------------------------------------------------------
// Utility functions used by the Unix port. Notably, our memory allocation;
// we use two separate allocators, one for long-lived stuff and one for
// stuff that gets freed after every regeneration of the model, to save us
// the trouble of freeing the latter explicitly.
// Utility functions used by the Unix port.
//
// Copyright 2008-2013 Jonathan Westhues.
// Copyright 2013 Daniel Richard G. <skunk@iSKUNK.ORG>
@ -64,16 +61,6 @@ void FreeAllTemporary() {
Head = NULL;
}
void *MemAlloc(size_t n) {
void *p = malloc(n);
ssassert(p != NULL, "Cannot allocate memory");
return p;
}
void MemFree(void *p) {
free(p);
}
std::vector<std::string> InitPlatform(int argc, char **argv) {
std::vector<std::string> args;
args.reserve(argc);

View File

@ -1,8 +1,5 @@
//-----------------------------------------------------------------------------
// Utility functions that depend on Win32. Notably, our memory allocation;
// we use two separate allocators, one for long-lived stuff and one for
// stuff that gets freed after every regeneration of the model, to save us
// the trouble of freeing the latter explicitly.
// Utility functions that depend on Win32.
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
@ -53,15 +50,6 @@ void FreeAllTemporary()
TempHeap = HeapCreate(HEAP_NO_SERIALIZE, 1024*1024*20, 0);
}
void *MemAlloc(size_t n) {
void *p = malloc(n);
ssassert(p != NULL, "Cannot allocate memory");
return p;
}
void MemFree(void *p) {
free(p);
}
std::vector<std::string> InitPlatform(int argc, char **argv) {
#if !defined(LIBRARY) && defined(_MSC_VER)
// We display our own message on abort; just call ReportFault.

View File

@ -150,8 +150,6 @@ std::vector<std::string> InitPlatform(int argc, char **argv);
void *AllocTemporary(size_t n);
void FreeAllTemporary();
void *MemAlloc(size_t n);
void MemFree(void *p);
// End of platform-specific functions
//================