Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. In my C++ code, I make extensive use of STL containers to ensure I *never* have to dynamically allocate memory.

In my C++ code, I make extensive use of STL containers to ensure I *never* have to dynamically allocate memory.

Scheduled Pinned Locked Moved Uncategorized
cpp
1 Posts 1 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • charette@mstdn.caC This user is from outside of this forum
    charette@mstdn.caC This user is from outside of this forum
    charette@mstdn.ca
    wrote last edited by
    #1

    In my C++ code, I make extensive use of STL containers to ensure I *never* have to dynamically allocate memory. Works great. Valgrind runs clean. Need a single object, return it. Need a bunch of objects, return a vector, map, set, etc.

    This codebase is the opposite. Everything is malloc() or new. The code I'm looking at right now is a simple vector of strings. The codebase does use std::vector. But instead of std::vector<std::string> they define it as a *pointer* to std::vector<char*>. Note even the vector itself is dynamically allocated. So they malloc() the memory for the vector (!?) and then malloc() each string.

    First thing I did was change malloc() to new and new[] across the codebase to ensure objects are created correctly. That solved a bunch of crashes.

    So much use of dynamic memory. Half the codebase is spent allocating memory, freeing it, checking to see if a function returned a nullptr or a pointer to an empty container.

    This whole thing needs to be re-written. #cpp

    1 Reply Last reply
    1
    0
    • R relay@relay.mycrowd.ca shared this topic
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups