Thread: declaring large array

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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
    838
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  5. #20
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

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, 01: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, 10:05 AM