Fast dynamic allocation of 3D array

This is a discussion on Fast dynamic allocation of 3D array within the C Programming forums, part of the General Programming Boards category; Originally Posted by Salem > But i have a global variable, i am doing a library for general proposes. Why ...

  1. #16
    Registered User
    Join Date
    Jul 2005
    Posts
    7
    Quote Originally Posted by Salem
    > But i have a global variable, i am doing a library for general proposes. Why i canīt use a global variable??
    Because I consider
    Code:
    Node3D ***foo = mem_node_matrix_3D(2,3,4);
    // some stuff
    free_net_3D ( foo );
    To be far more flexible than.

    Code:
    Node3D ***magicGlobalVariable;
    
    void somefunc ( void ) {
      magicGlobalVariable = mem_node_matrix_3D(2,3,4);
      // some stuff
      free_net_3D ( );
    }
    I mean what happens when you need two of these objects?

    Besides, did you fix the segfault or not?
    Yes , i havenīt the segmentation problem now!
    but how can i know if all the mem is free??

  2. #17
    Registered User
    Join Date
    Jul 2005
    Posts
    7
    Quote Originally Posted by Salem
    > But i have a global variable, i am doing a library for general proposes. Why i canīt use a global variable??
    Because I consider
    Code:
    Node3D ***foo = mem_node_matrix_3D(2,3,4);
    // some stuff
    free_net_3D ( foo );
    To be far more flexible than.

    Code:
    Node3D ***magicGlobalVariable;
    
    void somefunc ( void ) {
      magicGlobalVariable = mem_node_matrix_3D(2,3,4);
      // some stuff
      free_net_3D ( );
    }
    I mean what happens when you need two of these objects?

    Besides, did you fix the segfault or not?
    Aha!!, but i only need 1 object

  3. #18
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    > but how can i know if all the mem is free??
    Well the number of malloc calls matches the number of free calls. So long as you pass the pointer you got from malloc to free, all will be well (assuming you didn't pass a corrupt pointer, and it hasn't fallen over just yet).

    > Aha!!, but i only need 1 object
    Today - there's always tomorrow and any other program you may write.
    No need for sloppy implementation just because "I only need 1"
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Replies: 4
    Last Post: 11-02-2006, 10:41 AM
  3. Dynamic allocation of an array of strings
    By earth_angel in forum C Programming
    Replies: 3
    Last Post: 06-24-2005, 09:40 AM
  4. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM
  5. dynamic allocation question
    By vale in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 04:23 PM

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