Thread: array

  1. #1
    Unregistered
    Guest

    Question array

    Hi there,

    How to allocate a 2 dimension array using "new" operator?
    How to pass a 2 dimension array to a function?
    Is pointer always 4 bytes long or depends on system?


    Thank you

  2. #2
    Unregistered
    Guest
    type ** name;
    name = new type* [xlength];
    for(int i = 0; i < xlength; i++)
    {
    name[i] = new type[ylenght];
    }


    //passing 2D array to function
    foo(name);


    to my knowledge pointers are always 4 bytes long.

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    does a command like
    Code:
    char dummy[390][435906];
    allocate 390*435906 bytes?(give or take a few)

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    does a command like
    Code:
    char dummy[390][435906];
    allocate 390*435906 bytes?(give or take a few)

    well that would be 390 pointers (4 bytes each) to 390 different allocated areas of 435906 bytes. So i guess the minimum memory being allocated is (390*4)+(390*435906) = about 167Mb
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM