Array Management During Runtime
Im working on a octree class, I have it calculating the cubes(nodes) and i want to assign an array to each cube to hold the index of the objects in a list. The question i want to ask is that when declaring the array of indexs for each cube i obviously have to choose a default array size. If during runtime i reach this size and have to resize the array, this will obviously affect performance( specially as most of my objects are dynaimic). Is there an alternative or is this performance hit going to be managable?
I have though about using a string to hold the indexs, this would take up more storage if full but alot less when half full & wouldnt need resizing.
Does anyone have any pointers?
std::vector is not the only choice, you have std::deque too its also a random access container and is slightly more efficient for growth than vector (depends on the context though). std::deque with a custom allocator type such as boost::fast_pool_allocator gives excellent preformance in most cases. If elements stored in memory contiguously is of any significance to your context then go for vector its guaranteed contiguousness, you can still use custom allocator types with it and with all the standard library containers.
[Edited by - snk_kid on June 15, 2005 10:08:15 AM]
[Edited by - snk_kid on June 15, 2005 10:08:15 AM]
im using c# - can i still use stl? i dont imagine that the collection class is as good - i think it will cause a problem with boxing/unboxing.
Quote:Original post by Hibbs
im using c# - can i still use stl?
As of this moment not an elegant way no, how-ever STL.NET is coming very soon so you will be able to use in any .NET language, it wont make much of a difference in any case as it will be simillar to the current collections framework (storing object references) just with an STL style to it.
Quote:Original post by Hibbs
i think it will cause a problem with boxing/unboxing.
Well you have choice between ArrayList or writing a custom dynamic array type, the former is most definitely written to be as efficent as possible in C# (while still being as generic as possiable) such as efficently growing a naive method would grow by one element extra.
As far as i'm aware ArrayList grows by twice it's size when the capactiy is reached. With the former, be it using pre C# 2.0 only objects are stored in .NET collections so as you say primitive built-in types will be box/unboxed i'm not sure how much this effects preformance such that it makes it significant so you'll most likely need to profile.
With the latter you could write a custom dynamic array types that specifically create arrays of primitive built-in types that does all or most of the same operations as ArrayList but will it really be worth it, probably not.
[Edited by - snk_kid on June 16, 2005 7:39:35 AM]
I think that C# 2005 has improvemnts to storing object types and gets around the boxing problem. I think ill download the beta and check into it further.
DO you know if the STL.NET is being released as part of the 2005 version, or is it coming out seperate?
DO you know if the STL.NET is being released as part of the 2005 version, or is it coming out seperate?
Quote:Original post by Hibbs
DO you know if the STL.NET is being released as part of the 2005 version, or is it coming out seperate?
All i know is that STL.NET will be available for VC++ 2k5 release because of the new .NET language C++/CLI so its written there, not sure if you will be able to use it in other .NET languages in 2k5 straight away but i don't see why not.
STL.NET isn't currently in any beta of VC++ 2k5 express.
It seems that there is a new solution in 2005, that removes the boxing/unboxing, called "generics" - its possible to create a collection defined to use a basetype.
It dosnt look like they plan to have STL in anything but c++.
Ill probably end up kicking myself for deciding to use c#.
It dosnt look like they plan to have STL in anything but c++.
Ill probably end up kicking myself for deciding to use c#.
Quote:Original post by Hibbs
when declaring the array of indexs for each cube i obviously have to choose a default array size.
I don't think so... You can declare the arrat, and then instantiate the array dynamically at runtime using the new operator...
So you'll want Generic.List, its seems to be quite similar to ArrayList, you can set an initial capacity etc, etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement