dbghelp: Directly use Heap functions.
Markus Amsler
markus.amsler at oribi.org
Mon Apr 30 08:06:25 CDT 2007
Eric Pouech wrote:
> Markus Amsler a écrit :
>> Dmitry Timoshkov wrote:
>>> The old code at least bothered to actually free some memory.
>> Good point. I wasn't aware that some memory is only temporarily
>> used. I'm going to rework it.
>>
>> Markus
>>
>>
>>
>>
> does this patch gives you lots of improvements ?
> A+
>
> ------------------------------------------------------------------------
>
> diff --git a/dlls/dbghelp/storage.c b/dlls/dbghelp/storage.c
> index e196143..c3ccaf5 100644
> --- a/dlls/dbghelp/storage.c
> +++ b/dlls/dbghelp/storage.c
> @@ -73,30 +73,28 @@ void pool_destroy(struct pool* pool)
>
> void* pool_alloc(struct pool* pool, unsigned len)
> {
> - struct pool_arena** parena;
> struct pool_arena* arena;
> void* ret;
>
> len = (len + 3) & ~3; /* round up size on DWORD boundary */
> assert(sizeof(struct pool_arena) + len <= pool->arena_size && len);
>
> - for (parena = &pool->first; *parena; parena = &(*parena)->next)
> + for (arena = pool->first; arena; arena = arena->next)
> {
> - if ((char*)(*parena) + pool->arena_size - (*parena)->current >= len)
> + if ((char*)arena + pool->arena_size - arena->current >= len)
> {
> - ret = (*parena)->current;
> - (*parena)->current += len;
> + ret = arena->current;
> + arena->current += len;
> return ret;
> }
> }
> -
> +
> arena = HeapAlloc(GetProcessHeap(), 0, pool->arena_size);
> if (!arena) {FIXME("OOM\n");return NULL;}
>
> - *parena = arena;
> -
> ret = (char*)arena + sizeof(*arena);
> - arena->next = NULL;
> + arena->next = pool->first;
> + pool->first = arena;
> arena->current = (char*)ret + len;
> return ret;
> }
>
I cant try it at the moment, but I tried also the same approach. It went
down from 100s to around 27s compared to 18s with Heap functions. The
other problem here is, not all allocated memory is used, the gaps in not
first nodes never gets filled.
Also IMO memory allocation logic should only coded once.
I will try it with the HeapCreate/HeapDestroy for every
pool_init/pool_destroy as mentioned by Frank. Let's see what the
overhead of HeapCreate is.
Markus
More information about the wine-devel
mailing list