Jump to content
  • Advertisement
Sign in to follow this  
Hibbs

Array Management During Runtime

This topic is 4930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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#.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
So you'll want Generic.List, its seems to be quite similar to ArrayList, you can set an initial capacity etc, etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!