Exemplo n.º 1
0
bool ScenarioWorkload::run()
{
    if(func_calls->has_next() && allocators->has_next() &&
       alloc_sizes->has_next()) {
        switch(func_calls->next()) {
            case FunctionCalls::MALLOC: {
                memory_operation data = allocators->next()->wrapped_malloc(alloc_sizes->next());
                post_allocation_check(data);
                break;
            }
            case FunctionCalls::CALLOC: {
                memory_operation data = allocators->next()->wrapped_calloc(1,
                                                                           alloc_sizes->next());
                post_allocation_check(data);
                break;
            }
            case FunctionCalls::REALLOC: {
                //Guarantee the memory for realloc.
                Allocator *allocator = allocators->next();
                memory_operation to_realloc = allocator->wrapped_malloc(512);

                memory_operation data = allocator->wrapped_realloc(to_realloc.ptr,
                                                                   alloc_sizes->next());
                post_allocation_check(data);
                break;
            }
            case FunctionCalls::FREE: {
                memory_operation *data = get_allocated_memory();

                if(!allocations.empty() && (data != NULL)) {
                    allocator_factory.get_existing(data->allocator_type)->wrapped_free(data->ptr);
                    data->is_allocated = false;

                    memory_operation free_op = *data;
                    free_op.allocation_method = FunctionCalls::FREE;
                    allocations.push_back(free_op);
                }

                break;
            }
            default:
                assert(!"Function call identifier out of range.");
                break;
        }

        return true;
    }

    return false;
}
Exemplo n.º 2
0
void check_memory(char const * component_name) {
    if (g_max_memory != 0 && get_allocated_memory() > g_max_memory)
        throw memory_exception(component_name);
}