[PATCH 3/3] wined3d: Reduce the number of independent heap allocations.

Henri Verbeet hverbeet at gmail.com
Tue Oct 5 09:17:25 CDT 2021


On Tue, 5 Oct 2021 at 15:52, Jan Sikorski <jsikorski at codeweavers.com> wrote:
> > On 5 Oct 2021, at 15:33, Henri Verbeet <hverbeet at gmail.com> wrote:
> > We'd typically write that like this:
> >
> >    object = heap_alloc(...);
> >    ...
> >    object->resources = (struct wined3d_resource *)&object[1];
> >    ...
> >    object->uploads = (struct wined3d_deferred_upload
> > *)&object->resources[object->resource_count];
> >
> > etc.
>
> I’ve seen that elsewhere in the codebase, but I think it has some downsides. As is, each block of code only deals with a single field, and you can reorder these blocks around freely and add/remove without changing the ones next to it. Not that it’s a huge problem to do it, but are there reasons for this?
>
At the core, it's personal preference for the existing cases, and then
consistency with existing code for new code.

If being able to easily reorder these is really a concern, I could
live with something like the following:

    offset = 0;
    memory = heap_alloc(...);
    ...
    object = (struct wined3d_command_list *)&memory[offset];
    offset += sizeof(*object);
    ...
    object->resources = (struct wined3d_resource *)&memory[offset];
    offset += object->resource_count * sizeof(*object->resources);

I'm not sure that's really worth it, but the issue I have with the
existing patch is mostly the "void *" casts and using "+" instead of
"[]" for address calculations, not the "memory"/"offset" scheme per
se.



More information about the wine-devel mailing list