Storing and sorting objects on my engine

Started by
25 comments, last by brega 13 years, 6 months ago
@DieterVW
Quote:
...writing your own allocator...


Witch i don't know how. What is requirement for vector allocator?
What operators/functions do i need to implement in my allocator that
vector are using?

@mhagain
Quote:
You might find that just sorting them all anyway and skipping over the ones you don't want to render has less overhead than using a second list

That might be my last option if i don't find the other way around.
Advertisement
For fixed size allocation, reuse chunks of memory by inserting garbage memory into a linked list of pointers. The pointer to the next chunk will have a special place in each allocation. Each time you need a new allocation of that size, take out the first pointer from the list and reuse it. If the list is empty, make a new allocation. You may also use padding to the power of two so that you round up from your requirement and for example use 128 bytes for an 80 byte struct. Your initial allocation can be one big chunk divided into smaller parts by calculating new pointer addresses.
Dawoodoz,
you make my brain melt down.
Since i am a beginner i need to chew this one step a time so please try
and explain it to me.

1. Are you talking about some custom linked list container that you've made?

2.
Quote:
For fixed size allocation...

known number of elements in front?
something like vector::reserve but for list?

Quote:
reuse chunks of memory by inserting garbage memory into a linked list of pointers.

what is chunk? single element in a list?
what is garbage memory? list filled with (for example) same dummy element?

3.
Quote:
The pointer to the next chunk will have a special place in each allocation...

i don't get this, what this means?

And rest of text also is confusing for me.
Collections of pointers can be dynamic arrays with padding that you usually don't need to reallocate and reallocating an array of pointers is very fast when the memory runs out.
The pointer collections can refer to fixed size chunks that efficiently can be reused by your garbage list.

Each type of struct that you use with the system will have a void* pointer as it's first element that we call "next".
The list is a pointer to NULL if empty or the first struct otherwise.
Whenever you want to release an allocation, the "next" pointer will point to the old head of the list and the new head of the list will be a pointer to your "released" memory allocation. Therefor you don't need another allocation for the link list because it borrows memory from the items that you throw away.

A chunk is what I call a part of the memory without any datatype assigned to it.
When you allocate memory, you get a pointer to the beginning of the interval in the linear memory address space.

Here is good links with the things that you need to learn:
http://www.openismus.com/documents/cplusplus/cpointers.shtml
http://www.macs.hw.ac.uk/~rjp/Coursewww/Cwww/linklist.html
no need for the first link, i have already got that basic knowledge about pointers.
i have never tried to make my own linked list container but instead i use std::list one so i have no idea how this "system" manipulates elements. To me its just a "black box".
i will try to make my own tomorrow based on your second link (and ill try to find some others for reference) and your "ideas".
if i stuck i hope you don't mind continue helping me?
thanks greatly.
I don't mind helping but I might not be online when you post the next question.
I think that is appropriate to continue conversation on my problem in For Beginners forum

This topic is closed to new replies.

Advertisement