any concerns with static memory in C?

This is a discussion on any concerns with static memory in C? within the C Programming forums, part of the General Programming Boards category; Hi, I would like to know if there are any memory constraints in C regarding the largest possible size of ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    2

    Question any concerns with static memory in C?

    Hi,
    I would like to know if there are any memory constraints in C regarding the largest possible size of arrays.
    I have a structure, say ABC, which has another structure DEF. In DEF, there is an integer array of 4096 elements(static allocation). Can this integer array cause any memory problems?
    thanks.


    cal

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Only if you're using some ancient fossil compiler like Turbo C, which limits the size of any single object to 64K bytes.

    Or an embedded system, which typically have a very small amount of memory compared to your average desktop machine.
    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.

  3. #3
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    like
    int array[4096]
    ?
    On a modern computer, there should not be any problem. I have seen much larger arrays than that which experience no difficultly.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    2

    Exclamation

    hmm..

    ok.. i am using the VC++ 6.0 compiler (have no other choice)... the problem is something unique..
    this is wat i mean.. there is a structure like this...
    Code:
    typdef struct _def
    {
       int arr[4096];
       ;
    }def;
    
    typdef struct _xyz
    {
       ;
    }xyz;
    
    typedef struct _abc
    {
       def D1;
       xyz X1;
    }abc;
    this is the structure arrangement.. there is a function call to which i am passing the pointer to D1.

    Code:
    void func (def *D)
    {
       D->a1 = D->a2; // a1 and a2 are pointers
       D->b1 = D->b2; // b1 and b2 are integers
    }

    as soon as the function call completes, a structure pointer in the X1 structure of abc structure is corrupted. It loses its values, and everything else goes wrong from there...

    I tried malloc but even then, the same problem arises. with the end of the function call, a totally alien structure gets corrupted.

    any ideas?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps you can post some REAL code [a minimal example that shows the problem is the best thing], because your code as you've posted it makes absolutely no sense - mostly because you are mixing variables.

    Statically sized arrays in themselves are not a problem in a desktop machine (VC 6.0 indicates this), so it's probably something else that is going wrong. My suspicion would be that you are returning the address of a local variable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,024
    Oh yes, can you upgrade compiler? VC6 is kind of a fossil now, too. You can get newer version of Visual Studio Express for free, too.
    Newer versions of VS also typically have the ability to detect stack smashing - that is, when you overwrote memory on the stack where you shouldn't.
    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.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Sounds to me like your code is broken, and not any limitation on the size of the array.
    Posting actual code which crashes would be a lot better.

    Even though it's old, VC6 won't have tiny memory restrictions like DOS compilers.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 11:48 PM
  2. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 06:05 PM
  3. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 06:45 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM

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