This one puzzles me. Any particular reason you're using --i instead of i--? I can't make out any difference to a for-header.
Some kind of convention for reverse iteration?
Type: Posts; User: Araanor
This one puzzles me. Any particular reason you're using --i instead of i--? I can't make out any difference to a for-header.
Some kind of convention for reverse iteration?
Optimization. The class uses an array to store objects, I found this to be the most efficient and clean way to implement it.
The alternative would have been to do new ObjectType[someSize] when...
Ah, I see. Thank you.
You know, I thought I asked if it would work. Does the cast produce undefined behaviour?
Yes.
Here's how I do it now:
void *mMemory;
ObjectType *mObjectArray;
...
// Allocate memory
No, I don't want char. I don't even want an array of my_object. I want a region of memory where I can put my objects. CornedBee made a good post on how this is possible. I'd only be casting from...
You're right.
I realise the problems with messing around with memory management. If the class proves to be too much trouble, I'll eject it. But until then, I'll see it to a somewhat finished...
That's good advice, but I wanted deletion in constant time.
I'll keep the original type of the pointers - I just thought of a new kludge instead! Which is:
union
{
void *mMemory
ObjectType...
You'll just love to hear that this is the first class I'm writing. :D
Right, some background then. I had a chat with a professional game developer some time back where he told me he sped up their...
A linked list would imply links.
The class uses an array so the objects can be stored in sequence and not be fragmented across memory.
O(1) is achieved for insertion by inserting items at the end...
Sure.
Which is the problem, I just wanted a raw memory block.
Oh, the destructors, that's right... Always some detail.
Thank you, that looks better. I just settled for char after reading a...
Undefined, you say.
What if I do this:
delete[] (char *) mArray;
:D
Thanks.
I'm writing a fast list-class with an array underneath and insertion and deletion in O(1). I'd use the stl vector otherwise.
This discussion just touched an issue I'm contemplating.
First, I have an allocation that looks lite this:
ObjectType *mArray = (ObjectType *) new char[sizeof(ObjectType) * iInitialSize];
...