Lines Matching refs:mem
251 UToolMemory *mem;
257 mem=(UToolMemory *)uprv_malloc(sizeof(UToolMemory)+initialCapacity*size);
258 if(mem==NULL) {
262 mem->array=mem->staticArray;
264 uprv_strcpy(mem->name, name);
265 mem->capacity=initialCapacity;
266 mem->maxCapacity=maxCapacity;
267 mem->size=size;
268 mem->idx=0;
269 return mem;
273 utm_close(UToolMemory *mem) {
274 if(mem!=NULL) {
275 if(mem->array!=mem->staticArray) {
276 uprv_free(mem->array);
278 uprv_free(mem);
284 utm_getStart(UToolMemory *mem) {
285 return (char *)mem->array;
289 utm_countItems(UToolMemory *mem) {
290 return mem->idx;
295 utm_hasCapacity(UToolMemory *mem, int32_t capacity) {
296 if(mem->capacity<capacity) {
299 if(mem->maxCapacity<capacity) {
301 mem->name, (long)mem->maxCapacity);
306 if(capacity>=2*mem->capacity) {
308 } else if(mem->capacity<=mem->maxCapacity/3) {
309 newCapacity=2*mem->capacity;
311 newCapacity=mem->maxCapacity;
314 if(mem->array==mem->staticArray) {
315 mem->array=uprv_malloc(newCapacity*mem->size);
316 if(mem->array!=NULL) {
317 uprv_memcpy(mem->array, mem->staticArray, (size_t)mem->idx*mem->size);
320 mem->array=uprv_realloc(mem->array, newCapacity*mem->size);
323 if(mem->array==NULL) {
324 fprintf(stderr, "error: %s - out of memory\n", mem->name);
327 mem->capacity=newCapacity;
334 utm_alloc(UToolMemory *mem) {
336 int32_t oldIndex=mem->idx;
338 if(utm_hasCapacity(mem, newIndex)) {
339 p=(char *)mem->array+oldIndex*mem->size;
340 mem->idx=newIndex;
341 uprv_memset(p, 0, mem->size);
347 utm_allocN(UToolMemory *mem, int32_t n) {
349 int32_t oldIndex=mem->idx;
351 if(utm_hasCapacity(mem, newIndex)) {
352 p=(char *)mem->array+oldIndex*mem->size;
353 mem->idx=newIndex;
354 uprv_memset(p, 0, n*mem->size);