Пример #1
0
void*
MemPool_grab(MemoryPool *self, size_t amount) {
    INCREASE_TO_WORD_MULTIPLE(amount);
    self->last_buf = self->buf;

    // Verify that we have enough stocked up, otherwise get more.
    self->buf += amount;
    if (self->buf >= self->limit) {
        // Get enough mem from system or die trying.
        S_init_arena(self, amount);
        self->last_buf = self->buf;
        self->buf += amount;
    }

    // Track bytes we've allocated from this pool.
    self->consumed += amount;

    return self->last_buf;
}
Пример #2
0
void*
MemPool_Grab_IMP(MemoryPool *self, size_t amount) {
    MemoryPoolIVARS *const ivars = MemPool_IVARS(self);
    INCREASE_TO_WORD_MULTIPLE(amount);
    ivars->last_buf = ivars->buf;

    // Verify that we have enough stocked up, otherwise get more.
    ivars->buf += amount;
    if (ivars->buf >= ivars->limit) {
        // Get enough mem from system or die trying.
        S_init_arena(self, ivars, amount);
        ivars->last_buf = ivars->buf;
        ivars->buf += amount;
    }

    // Track bytes we've allocated from this pool.
    ivars->consumed += amount;

    return ivars->last_buf;
}