53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
return NULL;
memchunks_size = __memchunks_size + 1;
if (SIZE_MAX - __memchunks_size == 0 ||
memchunks_size > SIZE_MAX / sizeof(void*))
@throw [OFOutOfRangeException newWithObject: self];
if ((memchunks = realloc(__memchunks,
memchunks_size * sizeof(void*))) == NULL)
@throw [OFNoMemException newWithObject: self
andSize: memchunks_size];
if ((ptr = malloc(size)) == NULL) {
free(memchunks);
|
|
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
return NULL;
memchunks_size = __memchunks_size + 1;
if (SIZE_MAX - __memchunks_size == 0 ||
memchunks_size > SIZE_MAX / sizeof(void*))
@throw [OFOutOfRangeException newWithObject: self];
if ((memchunks = realloc(__memchunks,
memchunks_size * sizeof(void*))) == NULL)
@throw [OFNoMemException newWithObject: self
andSize: memchunks_size];
if ((ptr = malloc(size)) == NULL) {
free(memchunks);
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
iter = __memchunks + __memchunks_size;
while (iter-- > __memchunks) {
if (OF_UNLIKELY(*iter == ptr)) {
if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL))
@throw [OFNoMemException newWithObject: self
andSize: size];
*iter = ptr;
return ptr;
}
}
@throw [OFMemNotPartOfObjException newWithObject: self
andPointer: ptr];
return NULL; /* never reached, but makes gcc happy */
}
- (void*)resizeMem: (void*)ptr
toNItems: (size_t)nitems
ofSize: (size_t)size
{
size_t memsize;
if (ptr == NULL)
return [self getMemForNItems: nitems
ofSize: size];
if (nitems == 0 || size == 0) {
[self freeMem: ptr];
return NULL;
}
if (nitems > SIZE_MAX / size)
@throw [OFOutOfRangeException newWithObject: self];
|
|
|
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
iter = __memchunks + __memchunks_size;
while (iter-- > __memchunks) {
if (OF_UNLIKELY(*iter == ptr)) {
if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL))
@throw [OFNoMemException newWithObject: self
andSize: size];
*iter = ptr;
return ptr;
}
}
@throw [OFMemNotPartOfObjException newWithObject: self
andPointer: ptr];
return NULL; /* never reached, but makes gcc happy */
}
- (void*)resizeMem: (void*)ptr
toNItems: (size_t)nitems
ofSize: (size_t)size
{
size_t memsize;
if (ptr == NULL)
return [self getMemForNItems: nitems
ofSize: size];
if (nitems == 0 || size == 0) {
[self freeMem: ptr];
return NULL;
}
if (nitems > SIZE_MAX / size)
@throw [OFOutOfRangeException newWithObject: self];
|