1

I was reading this answer and maybe because I have never encountered this words, I don't understand what the user was mentioning in the first point of that answer, can someone use simpler words or an example to show what that statement means ?

Community
  • 1
  • 1
user2384250
  • 548
  • 5
  • 13
  • It means the relevant standard library component (e.g. vector) takes care of allocating all the memory it requires, and the use does not have to be concerned with how or where this happens (although you have some control over this via the allocators). – juanchopanza May 26 '13 at 10:03
  • 3
    @s3rius That is incorrect. "allocate memory internally" is no statement about performance or *amount* of memory used, only *that* those containers allocate memory themselves. –  May 26 '13 at 10:04
  • You're right. But it isn't a far jump to come to that conclusion. These are part of the reason things like EASTL were developed. But yes, this very statement isn't about performance or amount. Might as well get rid of it. – s3rius May 26 '13 at 10:06
  • @s3rius in fact, that jump is quite a long one. In my experience, when use of the standard library has slowed down an application, it has been through misuse, through lack of expertise. – juanchopanza May 26 '13 at 10:07
  • @juanchopanza so basically this is a description of the fact that I don't use the `new` operator _explicitly_ ? And why allocators are so interesting ? – user2384250 May 26 '13 at 10:09
  • In what context you are asking? – Dineshkumar May 26 '13 at 10:11
  • @user2384250 you don't call `new` and you don't even have to worry about whether `vector` calls it or not (the standard doesn't explicitly say anything about that). So memory allocation is abstracted and hidden away. But if you really care, the allocators allow you to say how and where you want the memory to be allocated. – juanchopanza May 26 '13 at 10:13
  • 2
    Also note that STL is most likely a misnomer. The standard template library (STL) formed the basis of a lot of what became the C++ standard library quite a long time ago. So it is more precise to talk about the C++ standard library, because that is what most people use when they write C++. – juanchopanza May 26 '13 at 10:24
  • @juanchopanza thanks, especially for the last part ;) – user2384250 May 26 '13 at 11:39

1 Answers1

3

When you use something like vectors or map ,... it belongs to STL (STANDARD TEMPLATE LIBRARY). you don't need to allocate memory as you do in arrays. In realtime the arrays are not sufficient and we cannot determine size.

STL containers will allocate memory internally, as you add elements to it. so there is good memory management. [if users manually allot, it might be not enough if alloted less or gets wasted if alloted too much memory].

Dineshkumar
  • 4,165
  • 5
  • 29
  • 43
  • 2
    `s/STL/standard library/g` - see [What's this STL vs. “C++ Standard Library” fight all about?](http://stackoverflow.com/q/5205491/395760) –  May 26 '13 at 11:36