Shared class members over Dll Boundary

This is a discussion on Shared class members over Dll Boundary within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by CornedBee I'm talking about the per-node allocation the map does. Also, static members of a template are ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,668
    Quote Originally Posted by CornedBee View Post
    I'm talking about the per-node allocation the map does.
    Also, static members of a template are per template instantiation. For every type you instantiate your smart pointer with, you get another map. Still, that overhead is really rather irrelevant - even if you instantiate the template for 200 types, it won't exceed a few k.
    I don't know how it is for templates, but I would find it silly that each template instance would get its own map, especially when the map does not hold any type of T, which it does not.
    However, in my current code, there's only one map because it's declared as a global variable inside the DLL (inside the MemoryManager namespace) which is returned by the GetStatics() function.

    Quote Originally Posted by CornedBee View Post
    I'm still talking about the per-allocation overhead. Suppose:
    Code:
    typedef CMemoryManager<int> int_ptr;
    typedef std::vector<int_ptr> ptr_vec;
    // Measure memory usage here.
    int *demo = new int;
    // Measure memory usage here.
    delete demo;
    ptr_vec manyPointers(100000);
    // Measure memory usage here.
    for(ptr_vec::iterator it = manyPointers.begin(); it != manyPointers.end(); ++it) {
      *it = new int;
    }
    // Measure memory usage here.
    The initial two measurements ought to tell you how much overhead new itself has. This is a guideline to measure the total overhead from your constructs. Every int is 4 bytes large, plus new's own overhead. Make that, for demonstration purposes, 12 bytes in total. Then the 100000 ints we allocate take 1200000 bytes of memory.
    The difference between the last two measurements minus the 1200000 bytes of the ints themselves tell you how much overhead you introduce.
    Does it matter? No? Unless I see memory running out, I'm not really phased by the overhead.
    Aside from keeping the memory safe, it's also thread safe and helps (at least will) in keeping your data on the heap thread safe, as well.
    And even so, with so much memory we have nowadays, I'm a little spoiled, and I have all the right to be!

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Oh, I very much disagree. Memory hogging is the nasty kind of behaviour I expect from .Net and Java programs, not C++ programs.

    Memory overhead is not just a problem because of the size it requires. It also makes cache behaviour worse.

    I also fail to see how this makes programs any safer. In fact, it encourages the unsafe practice of trying to turn a raw pointer back into a smart pointer.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,668
    Not very much unsafe, since it remembers every pointer is uses.
    Memory hogging is the least I'd call it, since the overhead is so very small even with such huge numbers. Memory hogging is eating 50+ MB of RAM at the very least and the memory manager won't do that at all.

  4. #19
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,674
    >> And even so, with so much memory we have nowadays, I'm a little spoiled
    If you're ever in an interview for an embedded development posistion......keep that to yourself

    gg

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,668
    LOL sure. But for PCs, I think there's not so many problems.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about class members and constructors
    By Megidolaon in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2009, 02:01 PM
  2. Replies: 3
    Last Post: 10-31-2005, 11:05 AM
  3. Private Static class members
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2005, 06:37 AM
  4. Protected Inheritance
    By golfinguy4 in forum C++ Programming
    Replies: 8
    Last Post: 12-27-2002, 09:56 AM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21