Witam,
bardzo proszę o pomoc w sprawie 'realloc'. Generalnie jest to implementacja stosu i w momencie kiedy nowy element, który chce zalokować użytkownik, się nie mieści powinniśmy wykorzystać właśnie tą problematyczną funkcję. Jakieś pomysły? Z góry dziękuję :)
void *u_push_stack( u_stack_t *stack, void *item, size_t size ) {
u_stack_t *newItem;
if( stack->counter == stack->capacity ) {
stack->counter = stack->capacity - size;
} else if ( stack->counter != stack->capacity ) {
stack->counter = stack->counter - size;
}
if ( stack->counter >= 0 ) {
//first
/*newItem->store = item;
newItem->current = stack -> current;
stack->current = item;*/
//second
stack->current = stack->current + size;
memcpy(stack->current, item, size);
//third
//*co = ((int*)stack->current - (int*)stack->store)/size;
//cout << "look " << *co << endl;
} else {
void* temp;
if( (temp = realloc(stack->store, stack->capacity + size)) != NULL ) {
stack->store = realloc(stack->store, stack->capacity - size);
}
}
}