【发布时间】:2011-12-16 06:29:09
【问题描述】:
当我在我的 iOS 应用程序中使用 realloc 时,它似乎总是将我的应用程序中的内存增加 2 的幂,而不是我指定的。
当我根据其存储的对象大小检查分配的大小时,这会导致一些问题。
这是 realloc 的设计方式还是我做错了什么?
typedef struct {
GLfloat r;
GLfloat g;
GLfloat b;
GLfloat a;
} Color;
typedef struct {
int objectID;
int modelID;
GLfloat scale;
GLfloat translation[3];
GLfloat rotation[3];
Color color;
bool render;
} Object;
Object* objects;
objects = realloc(objects, malloc_size(objects) + sizeof(Object));
NSLog(@"objects size = %lu", malloc_size(objects)); //prints 64 instead of 56
【问题讨论】:
标签: objective-c ios realloc