/* Create a chunk with a certain allocation unit ** -------------- */ PUBLIC HTChunk * HTChunkCreate ARGS1 (int,grow) { HTChunk * ch = typecalloc(HTChunk); if (ch == NULL) outofmem(__FILE__, "creation of chunk"); HTChunkInit (ch, grow); return ch; }
PUBLIC HTChunk * HTChunkCreateMayFail ARGS2 (int,grow, int,failok) { HTChunk * ch = typecalloc(HTChunk); if (ch == NULL) { if (!failok) { outofmem(__FILE__, "creation of chunk"); } else { return ch; } } HTChunkInit (ch, grow); ch->failok = failok; return ch; }
/* Create a chunk with a certain allocation unit and ensured size ** -------------- */ PUBLIC HTChunk * HTChunkCreate2 ARGS2 (int,grow, size_t, needed) { HTChunk * ch = typecalloc(HTChunk); if (ch == NULL) outofmem(__FILE__, "HTChunkCreate2"); HTChunkInit (ch, grow); if (needed > 0) { ch->allocated = needed-1 - ((needed-1) % ch->growby) + ch->growby; /* Round up */ CTRACE((tfp, "HTChunkCreate2: requested %d, allocate %d\n", (int) needed, ch->allocated)); ch->data = typecallocn(char, ch->allocated); if (!ch->data) outofmem(__FILE__, "HTChunkCreate2 data"); }
/* Create a chunk with a certain allocation unit and ensured size * -------------- */ HTChunk *HTChunkCreate2(int grow, size_t needed) { HTChunk *ch = typecalloc(HTChunk); if (ch == NULL) outofmem(__FILE__, "HTChunkCreate2"); HTChunkInit(ch, grow); if (needed > 0) { /* Round up */ ch->allocated = (int) (needed - 1 - ((needed - 1) % ch->growby) + (unsigned) ch->growby); CTRACE((tfp, "HTChunkCreate2: requested %d, allocate %u\n", (int) needed, (unsigned) ch->allocated)); ch->data = typecallocn(char, (unsigned) ch->allocated); if (!ch->data) outofmem(__FILE__, "HTChunkCreate2 data"); }