CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: space in string

  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    space in string

    Hello everyone,


    The space in string should use heap address memory space, not stack, right? But through debugging, for example,

    Code:
    string str = "hello";
    why I can not see the invocation of new operator? Anyone could point out where STL string class allocates space on heap and using which function to allocate please (any other approach other than using new to allocate space on heap?)?


    thanks in advance,
    George

  2. #2
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: space in string

    Yes the space in an std::string is allocated on the heap. It uses the new operator for this. I can't really think of any other decent way to dynamically allocate memory in C++. Well, there is malloc().
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  3. #3
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: space in string

    Quote Originally Posted by George2
    The space in string should use heap address memory space, not stack, right?
    There is nothing in the standard stating any requirement for how std::string allocates memory. Most implementations will use stack memory for small strings and heap memory for large ones.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  4. #4
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: space in string

    Thanks treuss,


    My question is answered.

    Quote Originally Posted by treuss
    There is nothing in the standard stating any requirement for how std::string allocates memory. Most implementations will use stack memory for small strings and heap memory for large ones.

    regards,
    George

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured