STD::Vector

preview_player
Показать описание
Watch the stream here:

#shorts #Advice #coding
Рекомендации по теме
Комментарии
Автор

To be fair, you could use std::vector with a custom allocator (then have you're allocator only pull from a fixed chunk of memory), but it really just sounds like you want a std::array

izikpfirrmann
Автор

you can use reserve() with std::vector. and also pass in a different allocator for different allocation strategies and even write your own tracker for memory usage.

Pure static fixed-size arrays have their place but are usually a bad idea. They may map with gaps when you load your program,

Putting them on the stack can be far worse for memory consumption than dynamic.

dont just distregard dynamic memory allocation because it's dynamic... its there to solve certain problems for you.

peterino
Автор

You can provide your own memory allocator (your own malloc) to std::vector, it has this parameter as template. Only thing you need is to create an additional allocator class with methods to allocate/free memory, that's the place where you can use your own memory managment (bump allocator, memory pool, static memory, etc.) and you provide this class as a template type to std::vector.
So that's way, you can still use functionality of std::vector but with your own memory managment.
a.k.a : you may just don't like template container of STL, that's the main reason you don't use it I think. I personally always use them in the beginning of developing project, just because I learn them a long time ago as a software engineer.

cheerwizard
Автор

even if there are more reasons why someone want to avoid std vectors. std::vectors has a reserve() function for increasing its capacity to avoid reallocation until you reached that chosen capacity. But I don’t think there is a big problem of doing your own simplified vector version to avoid compilation time perhaps or what not

foxidgamedev
Автор

Is that the monkey meadow layout on the map?

Fluffkin-the-Femboy
Автор

Hey we did that too, but that was over 25 years ago when memory was still scarce 😅
Nowadays you can use gigs and gigs of memory and still no end to it.
I mean my smartphone has over 500 times the memory of my first computer

Frank-xued