hehe, no worries, just getting out of hand. I did like your post before the edit though.gravaera wrote:EDIT: @tantrikwizard: I had just typed me up a beautiful discourse on the evils of gotos, with witty little detours, and intellectually engaging points. Great timing.
I am the OP BTW, but perhaps I should have labelled the thread 'Algorithm Challenge' or something like that? I hoped the bug would jump out at somebody as obvious. Theres a couple bugs or a single bug manifesting itself in a couple ways which doesn't appear unless two or more threads are hitting it simultaniously. It's not a confusing algorithm (even with the gotos) which is what has me confused. The basic idea is to avoid blocking. In my experience you get better performance by using atomic operations rather than blocking especially if the code stays in user space and doesnt cross the kernel boundary. Even if the code must do extra computations to remain in user space it's normally faster (unless the code is crap).gravaera wrote:But anyway, @OP: You'll find that you'll probably get more help if you provide a real synopsis of the AREa where you think you need pointers. you just came and dumped code and expected us to figure out it intricacies. Why not post a smaller snippet with something more specific to ask?
The basic rundown is this:
- when creating a virtual address space a process level PartitionAllocator is handed off to user space for allocating/freeing heap memory.
- the PartitionAllocator is intially setup with a single free partition at the base of user space which defines the entire user memory space (No next pointer and size==sizeof(entire user memory))
- as allocation requests come in it iterates through the _FreePartitions list until it finds a partition large enough for the request.
- it atomically decreses the requested size and uses the failure of this atomic operation for concurrency control.
- next it atomically pushes the new allocation on the _UsedPartitions and returns the pointer to the caller
- it first locates and atomically removes the requested used partition from the _UsedPartitions list.
- it then iterates through the _FreePartitions checking if the address prepends an existing free partition. If it does the new partition is resized to include both partitions and replaces the existing partition.
- next it checks whether the address extends an existing partition, if so it expands the existing partition to include the freed space.
What am I missing? I cant think of anything. After staring at a hunk of code for too long it all runs together and doesnt make any sense anymore. My eyes are bleeding over this otherwise simple algorithm. Thanks for the help everyone.