Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here here and here here.

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here.

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here.

added 94 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

a A working stack allocator

Here's an absolutely essential piece of C++C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of:

, http://stackoverflow.com/questions/783944/how-do-i-allocate-a-stdstring-on-the-stack-using-glibcs-string-implementationhere

and http://stackoverflow.com/questions/11648202/questions-about-hinnants-stack-allocatorhere .

TroubleThe trouble was, neither of them waswere working with gcc-4.8gcc-4.8, and both needed fixing. Here's a fixed version of Hinant's allocator. Could there some improvement or fix to still be made?

After running the above example under valgrindvalgrind, it will report:

==25600== HEAP SUMMARY:
==25600== in use at exit: 0 bytes in 0 blocks
==25600== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==25600== 
==25600== All heap blocks were freed -- no leaks are possible
==25600== 
==25600== For counts of detected and suppressed errors, rerun with: -v
==25600== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
==25600== HEAP SUMMARY:
==25600== in use at exit: 0 bytes in 0 blocks
==25600== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==25600== 
==25600== All heap blocks were freed -- no leaks are possible
==25600== 
==25600== For counts of detected and suppressed errors, rerun with: -v
==25600== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

a working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of:

http://stackoverflow.com/questions/783944/how-do-i-allocate-a-stdstring-on-the-stack-using-glibcs-string-implementation

http://stackoverflow.com/questions/11648202/questions-about-hinnants-stack-allocator

Trouble was neither of them was working with gcc-4.8, both needed fixing. Here's a fixed version of Hinant's allocator. Could there some improvement or fix still be made?

After running the above example under valgrind, it will report:

==25600== HEAP SUMMARY:
==25600== in use at exit: 0 bytes in 0 blocks
==25600== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==25600== 
==25600== All heap blocks were freed -- no leaks are possible
==25600== 
==25600== For counts of detected and suppressed errors, rerun with: -v
==25600== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

A working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here .

The trouble was, neither of them were working with gcc-4.8, and both needed fixing. Here's a fixed version of Hinant's allocator. Could there some improvement or fix to still be made?

After running the above example under valgrind, it will report:

==25600== HEAP SUMMARY:
==25600== in use at exit: 0 bytes in 0 blocks
==25600== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==25600== 
==25600== All heap blocks were freed -- no leaks are possible
==25600== 
==25600== For counts of detected and suppressed errors, rerun with: -v
==25600== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Source Link
user1095108
  • 1.5k
  • 2
  • 17
  • 29
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /