Thread: Problem with static STL i.e. map

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    2

    Problem with static STL i.e. map

    I am getting coredump on linux (Red Hat 3.4.6-8).
    I am using gcc (GCC) 3.4.6 20060404 compiler.

    The problem is I have used a static map inside a function (making the map local to the function). This function is in libStreet.so Now at run time another host application is loading this libStreet.so , using it and then unloading it.Everything works fine,But when host application closes[i.e. exits] It is giving coredump.If I change static map to static vector then it works fine[no coredump while closing host application.].

    I know that the static variables get deallocated after exiting from main() of host application, please let me know if my understanding is correct.

    In my case host application crashes after exiting main, however replacing the map with a vector solves the problem. Can anyone please help on this issue, Thanks.

    Please note that the same code works fine on Sun Solaris, gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath) version

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    2

    deallocation of static STL

    My questions are,

    1.Exactly when static variables in libStreet.so gets deallocated[After unloading libStreet.so or after exiting from main() of host apllication].
    2.STL grows at runtime if needed and variables marked as static gets space in .obj at compile time i.e. fixed amount of space[not absolute memory location but the offset].Then how does compiler handles allocation and deallocation of variables of type static STL[i.e. static map,vector,..].
    3.In our case host application crashes after exiting main[after unloading libStreet.so].It means static map is getting destructed after exiting main.It conflicts with 2nd point[allocation of space for static variable in .obj]
    4.Also if static variables which are from libStreet.so are getting destructed after exiting main() of host application and libStreet.so is already unloaded then how does host application gets access of the destructors of static type which are declared in libStreet.so .

    Could anybody please help on this issue,Thanks in advance.
    Last edited by laserlight; 10-26-2007 at 03:07 AM. Reason: Merged duplicate threads.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://www.dwheeler.com/program-libr...libraries.html
    Pay attention to the "Instead, libraries should export routines using the __attribute__((constructor)) and __attribute__((destructor)) function attributes" information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. STL Map Object
    By nomes in forum C++ Programming
    Replies: 6
    Last Post: 09-11-2003, 01:51 PM
  2. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  3. Unsorted Map and Multimap :: STL
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 12-21-2002, 11:22 PM
  4. Map and Functor :: STL
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 11-26-2002, 12:09 PM
  5. Searching STL Map Inside STL Map Object :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2002, 09:11 AM