declaring large array

This is a discussion on declaring large array within the C++ Programming forums, part of the General Programming Boards category; Things like window handles, bitmap handles, mutexes, etc, etc....

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    Things like window handles, bitmap handles, mutexes, etc, etc.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> this seems like it could be a lot cleaner in C++.
    Using vectors would be a lot cleaner in C++. You wouldn't have to worry about the potential bugs that exist in either version.

  3. #18
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    is a vector of much use if the collection is of a fixed size?


    and on that note...@OP:

    are your data sets always 6000 elements, or are you just always allocating the maximum amount you'd need?

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    It will still get rid of the need to delete what you allocated, which can get tricky in large programs.
    Plus it can perform bounds checking, which helps you find bugs.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  5. #20
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> is a vector of much use if the collection is of a fixed size?
    If they are dynamically allocated, yes. Three immediate examples are:
    1. The potential errors from the lack of a copy constructor and copy assignment operator in your struct would not be a problem because the default (compiler generated) versions of those functions would work correctly with vectors.
    2. The potential memory leak in your code when an allocation fails in the constructor would not happen with vectors.
    3. You would not need to write your own destructor.

    For non-dynamically allocated arrays I would consider std::tr1::array for the bounds checking and size advantages.
    Last edited by Daved; 06-02-2008 at 01:45 PM.

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

Similar Threads

  1. Stack Overflow when declaring array
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2009, 05:00 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. help with declaring array in which the user specifies size
    By ibanezrgking in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 09:05 AM

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