Jump to content
  • Advertisement
Sign in to follow this  
stefan5000

Unity Alternative for std::vector/STL?

This topic is 4461 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

Hi everybody, A few months ago in one of my projects I used the std::vector class. I restarted my project and am working on small executables / 64K apps. But because of this - I lost the opportunity to use the std::vector class. Is there a possibility to include it in my projects? I like this class. It is very easy to use, I think (okay - the parts of it I need). So...Any alternatives for std::vector/STL??? thx! cu

Share this post


Link to post
Share on other sites
Advertisement
Well, if your data is static, you could just use a standard c-array. If you do need the flexibility of a vector, it is pretty easy to make a simple one yourself.

The class contains a templated pointer and the size of the array. Whenever you need more space in the array, copy its contents to another array, re-new the original array to twice the size, then copy the data back. Add in a few functions to push_back and overload the [] operator and you are set...

Share this post


Link to post
Share on other sites
What makes you think the standard vector takes up more space than any alternative?

Share this post


Link to post
Share on other sites
I agree with Sr_Guapo, if you're making a tiny exe, then you'll most likely want to write your own vector class so you have as much control over it as possible. An array would probably result in less code, so long as it doesn't need resized often.

Share this post


Link to post
Share on other sites
You should just write your own vector class, in most cases it is just a linked list. If you need any advice on how to make it just let us know.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
You should just write your own vector class, in most cases it is just a linked list. If you need any advice on how to make it just let us know.


He shouldn't write a vector class as a linked list, he should write a linkedlist (or list/slist as C++ calls it) class as a linked list. Also I agree if you need a small executable, then STL shouldn't be used. Your own, non-templated (templates, in most cases create code for every template class), class might be the best idea.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
What makes you think the standard vector takes up more space than any alternative?


He doesn't mean overhead from the stl-vector implementation,
but space overhead from linking with the stl - which will make
his 64kb demo bigger (eg stlport.lib is 950 kb big).

And it shouldn't be too difficult to make your own custom
vector-template which doesn't depend on anything... Again, usually
I would advice against custom vector/list/... implementation, but
for a 64kb demo I can see whe he wants to do it that way.

Share this post


Link to post
Share on other sites
The reason I said write a "vector" class is so that he would write a class using the same naming convntion and functions that he is used to.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by CTar
Quote:
Original post by TheTroll
You should just write your own vector class, in most cases it is just a linked list. If you need any advice on how to make it just let us know.


He shouldn't write a vector class as a linked list, he should write a linkedlist (or list/slist as C++ calls it) class as a linked list. Also I agree if you need a small executable, then STL shouldn't be used. Your own, non-templated (templates, in most cases create code for every template class), class might be the best idea.

I've read about at least one implementation of the vector class which is incredibly efficient, and rather clever in my book, regarding code size. It specializes std::vector<void*>, I believe, and implements just about all of the code there. Then for every other type of std::vector, it inherits from std::vector<void*>, and the only additional code it needs to add is a few functions that contain a reinterpret_cast<>() call, which takes very little space (possibly no space?) code-wise.

If you do write your own vector class, it wouldn't hurt to look at the code for an already implemented version. You might find some useful things in there.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
You should just write your own vector class, in most cases it is just a linked list. If you need any advice on how to make it just let us know.

theTroll


Its my understanding that in all cases its continous memory, that's part of the spec. You can't legally implement a vector as a linked list.

Ahh, I see you clarified your point. I'll accept that logic:)

Cheers
Chris

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!