Lines Matching defs:mem
219 UToolMemory *mem;
225 mem=(UToolMemory *)uprv_malloc(sizeof(UToolMemory)+initialCapacity*size);
226 if(mem==NULL) {
230 mem->array=mem->staticArray;
232 uprv_strcpy(mem->name, name);
233 mem->capacity=initialCapacity;
234 mem->maxCapacity=maxCapacity;
235 mem->size=size;
236 mem->idx=0;
237 return mem;
241 utm_close(UToolMemory *mem) {
242 if(mem!=NULL) {
243 if(mem->array!=mem->staticArray) {
244 uprv_free(mem->array);
246 uprv_free(mem);
252 utm_getStart(UToolMemory *mem) {
253 return (char *)mem->array;
257 utm_countItems(UToolMemory *mem) {
258 return mem->idx;
263 utm_hasCapacity(UToolMemory *mem, int32_t capacity) {
264 if(mem->capacity<capacity) {
267 if(mem->maxCapacity<capacity) {
269 mem->name, (long)mem->maxCapacity);
274 if(capacity>=2*mem->capacity) {
276 } else if(mem->capacity<=mem->maxCapacity/3) {
277 newCapacity=2*mem->capacity;
279 newCapacity=mem->maxCapacity;
282 if(mem->array==mem->staticArray) {
283 mem->array=uprv_malloc(newCapacity*mem->size);
284 if(mem->array!=NULL) {
285 uprv_memcpy(mem->array, mem->staticArray, mem->idx*mem->size);
288 mem->array=uprv_realloc(mem->array, newCapacity*mem->size);
291 if(mem->array==NULL) {
292 fprintf(stderr, "error: %s - out of memory\n", mem->name);
295 mem->capacity=newCapacity;
302 utm_alloc(UToolMemory *mem) {
304 int32_t oldIndex=mem->idx;
306 if(utm_hasCapacity(mem, newIndex)) {
307 p=(char *)mem->array+oldIndex*mem->size;
308 mem->idx=newIndex;
309 uprv_memset(p, 0, mem->size);
315 utm_allocN(UToolMemory *mem, int32_t n) {
317 int32_t oldIndex=mem->idx;
319 if(utm_hasCapacity(mem, newIndex)) {
320 p=(char *)mem->array+oldIndex*mem->size;
321 mem->idx=newIndex;
322 uprv_memset(p, 0, n*mem->size);