Index: src/Cube.mm ================================================================== --- src/Cube.mm +++ src/Cube.mm @@ -343,19 +343,10 @@ [Cube.sharedInstance showMessage:msg]; [OFApplication terminateWithStatus:1]; } -void * -alloc(int s) // for some big chunks... most other allocs use the memory pool -{ - void *b = calloc(1, s); - if (!b) - fatal(@"out of memory!"); - return b; -} - void quit() // normal exit { [Cube.sharedInstance quit]; } Index: src/clientgame.mm ================================================================== --- src/clientgame.mm +++ src/clientgame.mm @@ -98,11 +98,11 @@ } dynent * newdynent() // create a new blank player or monster { - dynent *d = (dynent *)malloc(sizeof(dynent)); + dynent *d = (dynent *)OFAllocMemory(1, sizeof(dynent)); d->o.x = 0; d->o.y = 0; d->o.z = 0; d->yaw = 270; d->pitch = 0; @@ -183,12 +183,11 @@ } void zapdynent(dynent *&d) { - if (d) - free(d); + OFFreeMemory(d); d = NULL; } extern int democlientnum; @@ -279,13 +278,13 @@ } } lastmillis = millis; } +// brute force but effective way to find a free spawn spot in the map void -entinmap(dynent * - d) // brute force but effective way to find a free spawn spot in the map +entinmap(dynent *d) { loopi(100) // try max 100 times { float dx = (rnd(21) - 10) / 10.0f * i; // increasing distance float dy = (rnd(21) - 10) / 10.0f * i; Index: src/editing.mm ================================================================== --- src/editing.mm +++ src/editing.mm @@ -245,11 +245,11 @@ int t = 0; loopvrev(undos) { t += undos[i]->xs * undos[i]->ys * sizeof(sqr); if (t > maxremain) - free(undos.remove(i)); + OFFreeMemory(undos.remove(i)); } } void makeundo() @@ -266,21 +266,21 @@ conoutf(@"nothing more to undo"); return; } block *p = undos.pop(); blockpaste(*p); - free(p); + OFFreeMemory(p); } block *copybuf = NULL; void copy() { EDITSELMP; if (copybuf) - free(copybuf); + OFFreeMemory(copybuf); copybuf = blockcopy(sel); } void paste() Index: src/protos.h ================================================================== --- src/protos.h +++ src/protos.h @@ -138,11 +138,10 @@ extern void computeraytable(float vx, float vy); extern int isoccluded(float vx, float vy, float cx, float cy, float csize); // main extern void fatal(OFString *s, OFString *o = @""); -extern void *alloc(int s); // rendertext extern void draw_text(OFString *string, int left, int top, int gl_num); extern void draw_textf( OFConstantString *format, int left, int top, int gl_num, ...); Index: src/rendercubes.mm ================================================================== --- src/rendercubes.mm +++ src/rendercubes.mm @@ -16,14 +16,13 @@ } void reallocv() { - verts = (vertex *)realloc(verts, (curmaxverts *= 2) * sizeof(vertex)); + verts = + (vertex *)OFResizeMemory(verts, (curmaxverts *= 2), sizeof(vertex)); curmaxverts -= 10; - if (!verts) - fatal(@"no vertex memory!"); setarraypointers(); } // generating the actual vertices is done dynamically every frame and sits at // the leaves of all these functions, and are part of the cpu bottleneck on Index: src/rendergl.mm ================================================================== --- src/rendergl.mm +++ src/rendergl.mm @@ -139,11 +139,11 @@ void *scaledimg = s->pixels; if (*xs != s->w) { conoutf(@"warning: quality loss: scaling %@", IRI.string); // for voodoo cards under linux - scaledimg = alloc(*xs * *ys * 3); + scaledimg = OFAllocMemory(1, *xs * *ys * 3); gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, *xs, *ys, GL_UNSIGNED_BYTE, scaledimg); } if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, *xs, *ys, GL_RGB, Index: src/serverutil.mm ================================================================== --- src/serverutil.mm +++ src/serverutil.mm @@ -106,12 +106,12 @@ if (mapsize <= 0 || mapsize > 256 * 256) return; copyname = mapname; copysize = mapsize; if (copydata) - free(copydata); - copydata = (uchar *)alloc(mapsize); + OFFreeMemory(copydata); + copydata = (uchar *)OFAllocMemory(1, mapsize); memcpy(copydata, mapdata, mapsize); } ENetPacket * recvmap(int n) Index: src/tools.h ================================================================== --- src/tools.h +++ src/tools.h @@ -23,10 +23,12 @@ # include #else # include #endif +#import + #ifdef NULL # undef NULL #endif #define NULL 0 @@ -125,11 +127,11 @@ int ulen; vector() { alen = 8; - buf = (T *)malloc(alen * sizeof(T)); + buf = (T *)OFAllocMemory(alen, sizeof(T)); ulen = 0; } ~vector() { @@ -210,11 +212,11 @@ } void realloc() { - buf = (T *)::realloc(buf, (alen *= 2) * sizeof(T)); + buf = (T *)OFResizeMemory(buf, (alen *= 2), sizeof(T)); } T remove(int i) { Index: src/world.mm ================================================================== --- src/world.mm +++ src/world.mm @@ -421,22 +421,22 @@ setupworld(int factor) { ssize = 1 << (sfactor = factor); cubicsize = ssize * ssize; mipsize = cubicsize * 134 / 100; - sqr *w = world = (sqr *)alloc(mipsize * sizeof(sqr)); + sqr *w = world = (sqr *)OFAllocZeroedMemory(mipsize, sizeof(sqr)); loopi(LARGEST_FACTOR * 2) { wmip[i] = w; w += cubicsize >> (i * 2); } } +// main empty world creation routine, if passed factor -1 will enlarge old +// world by 1 void -empty_world( - int factor, bool force) // main empty world creation routine, if passed - // factor -1 will enlarge old world by 1 +empty_world(int factor, bool force) { if (!force && noteditmode()) return; cleardlights(); pruneundos(); @@ -493,11 +493,11 @@ } calclight(); startmap(@"base/unnamed"); if (oldworld) { - free(oldworld); + OFFreeMemory(oldworld); toggleedit(); execute(@"fullbright 1"); } } Index: src/worldlight.mm ================================================================== --- src/worldlight.mm +++ src/worldlight.mm @@ -236,11 +236,12 @@ // utility functions also used by editing code block * blockcopy(block &s) { - block *b = (block *)alloc(sizeof(block) + s.xs * s.ys * sizeof(sqr)); + block *b = (block *)OFAllocZeroedMemory( + 1, sizeof(block) + s.xs * s.ys * sizeof(sqr)); *b = s; sqr *q = (sqr *)(b + 1); for (int x = s.x; x < s.xs + s.x; x++) for (int y = s.y; y < s.ys + s.y; y++) *q++ = *S(x, y);