some question about memory allocation not enough

Discussion in 'C Programming' started by miloody, May 9, 2009.

  1. miloody

    miloody Guest

    Dear all:
    My pc installed 2G DRAM, but when I compile a source code like below:

    typedef struct _Y_Block{
    unsigned char uData[16][16];
    }Y_Block;

    int main(void){
    Y_Block ppYTmpblocks[1920/16][1920/16];
    Y_Block ppUTmpblocks[1920/8][1920/8];
    Y_Block ppVTmpblocks[1920/8][1920/8];
    ppVTmpblocks[1920/8][1920/8].uData[0][0]=0x12; //xxxx
    return 0;
    }

    The os will say "Program received signal SIGSEGV, Segmentation fault.
    main () at test.c:9"
    Does that mean my memory is really not enough?
    if the problem doesn't come from memory, where I can fix it?
    appreciate your help,
    miloody
     
    miloody, May 9, 2009
    #1
    1. Advertising

  2. miloody

    Eric Sosman Guest

    miloody wrote:
    > Dear all:
    > My pc installed 2G DRAM, but when I compile a source code like below:
    >
    > typedef struct _Y_Block{
    > unsigned char uData[16][16];
    > }Y_Block;
    >
    > int main(void){
    > Y_Block ppYTmpblocks[1920/16][1920/16];
    > Y_Block ppUTmpblocks[1920/8][1920/8];
    > Y_Block ppVTmpblocks[1920/8][1920/8];
    > ppVTmpblocks[1920/8][1920/8].uData[0][0]=0x12; //xxxx
    > return 0;
    > }
    >
    > The os will say "Program received signal SIGSEGV, Segmentation fault.
    > main () at test.c:9"
    > Does that mean my memory is really not enough?
    > if the problem doesn't come from memory, where I can fix it?
    > appreciate your help,


    This is Question 16.3 in the comp.lang.c Frequently
    Asked Questions (FAQ) list, <http://www.c-faq.com/>.

    --
    Eric Sosman
    lid
     
    Eric Sosman, May 9, 2009
    #2
    1. Advertising

  3. In article <>,
    miloody <> wrote:

    > Y_Block ppVTmpblocks[1920/8][1920/8];
    > ppVTmpblocks[1920/8][1920/8].uData[0][0]=0x12; //xxxx


    The subscripts for ppVTmpblocks run from 0 to 1920/8 - 1, so you
    are setting a non-existent element.

    You also probably don't have enough stack space available; how to fix
    that depends on your operating system. For unix with bash, look up
    "ulimit".

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.
     
    Richard Tobin, May 9, 2009
    #3
  4. (Richard Tobin) writes:
    > In article
    > <>,
    > miloody <> wrote:
    >
    >> Y_Block ppVTmpblocks[1920/8][1920/8];
    >> ppVTmpblocks[1920/8][1920/8].uData[0][0]=0x12; //xxxx

    >
    > The subscripts for ppVTmpblocks run from 0 to 1920/8 - 1, so you
    > are setting a non-existent element.
    >
    > You also probably don't have enough stack space available; how to fix
    > that depends on your operating system. For unix with bash, look up
    > "ulimit".


    Tweaking the OS settings so that one particular invocation of the
    program has enough stack space is one solution, but a better one is
    probably to arrange for the program not to use so much stack space.

    (Lengthy quibbling about the meaning of "stack" omitted.)

    And as Eric said, this is question 16.3 of the clc FAQ.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, May 9, 2009
    #4
  5. miloody

    Old Wolf Guest

    On May 10, 1:34 am, Eric Sosman <> wrote:
    >      This is Question 16.3 in the comp.lang.c Frequently
    > Asked Questions (FAQ) list, <http://www.c-faq.com/>.


    That FAQ entry isn't very well written IMHO.
    I'm sure Han or someone could come up with
    a more useful description!
     
    Old Wolf, May 10, 2009
    #5
  6. miloody

    miloody Guest

    Hi:
    On May 11, 12:17 am, "Malcolm McLean" <>
    wrote:
    > "miloody" <> wrote in message
    >
    > [program with large objects on the stack and and off-by-one access error
    > snipped]
    >
    > In a structured program with subroutines arranged in a roughly balanced
    > tree, subroutine depth grows logarithmically as a fucntion of program
    > complexity. However the total amount of data the program operates on will
    > tend to grow linearly with program complexity.
    >
    > What this means is that stacks can be very small, which means we can
    > potentially put them into a fast area ofmemory, like the primary cache.
    > However we have to be disciplined in excluding large objects from the stack
    > and putting them in dynamicmemoryallocated with malloc. (Or creating them
    > as globals. Sometimes it is better to have a large object as a global).

    My problem has been solved if I use malloc rather than declare those
    variables in my functions.
    I think the problems come from un-enough stack size.
    But I type ulimit, and it says unlimited like below.
    Does that really mean my stack is unlimited?

    root@T43:/# ulimit
    unlimited
    root@T43:/#

    appreciate your help,
    miloody
     
    miloody, May 12, 2009
    #6
  7. miloody

    James Kuyper Guest

    miloody wrote:
    ....
    > But I type ulimit, and it says unlimited like below.
    > Does that really mean my stack is unlimited?
    >
    > root@T43:/# ulimit
    > unlimited
    > root@T43:/#


    No, what ulimit tells you about is externally imposed upper limits.
    You're still limited by the total amount of memory available.
     
    James Kuyper, May 12, 2009
    #7
  8. James Kuyper <> writes:

    > miloody wrote:
    > ...
    >> But I type ulimit, and it says unlimited like below.
    >> Does that really mean my stack is unlimited?
    >>
    >> root@T43:/# ulimit
    >> unlimited
    >> root@T43:/#

    >
    > No, what ulimit tells you about is externally imposed upper
    > limits. You're still limited by the total amount of memory available.


    Also, on most shells `ulimit' without arguments tells you about the
    limit on the size of files created by the shell. You probably want
    `ulimit -s'.
     
    Nate Eldredge, May 12, 2009
    #8
  9. miloody

    miloody Guest

    Hi

    >On May 13, 12:36 am, Nate Eldredge <> wrote:
    > James Kuyper <> writes:
    > > miloody wrote:
    > > ...
    > >> But I type ulimit, and it says unlimited like below.
    > >> Does that really mean my stack is unlimited?

    >
    > >> root@T43:/# ulimit
    > >> unlimited
    > >> root@T43:/#

    >
    > > No, what ulimit tells you about is externally imposed upper
    > > limits. You're still limited by the total amount of memory available.

    >
    > Also, on most shells `ulimit' without arguments tells you about the
    > limit on the size of files created by the shell. You probably want
    > `ulimit -s'.

    I can see the stack size by ulimit like below.
    (I should use the right option.)
    root@T43# ulimit -a
    core file size (blocks, -c) 0
    data seg size (kbytes, -d) unlimited
    scheduling priority (-e) 0
    file size (blocks, -f) unlimited
    pending signals (-i) 16374
    max locked memory (kbytes, -l) 32
    max memory size (kbytes, -m) unlimited
    open files (-n) 1024
    pipe size (512 bytes, -p) 8
    POSIX message queues (bytes, -q) 819200
    real-time priority (-r) 0
    stack size (kbytes, -s) 8192
    cpu time (seconds, -t) unlimited
    max user processes (-u) 16374
    virtual memory (kbytes, -v) unlimited
    file locks (-x) unlimited
    root@T43#
    appreciate your help,
    miloody
     
    miloody, May 13, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SFoley

    ASP.NET not using enough memory?

    SFoley, Jul 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    455
    Craig Scurlock
    Jul 29, 2003
  2. =?Utf-8?B?RGVlcmFq?=

    Not enough memory for operation

    =?Utf-8?B?RGVlcmFq?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,951
    =?Utf-8?B?RGVlcmFq?=
    Jul 11, 2005
  3. tony lincoln

    excel---HSSF---not enough memory?

    tony lincoln, Mar 1, 2004, in forum: Java
    Replies:
    0
    Views:
    933
    tony lincoln
    Mar 1, 2004
  4. Ken
    Replies:
    24
    Views:
    3,928
    Ben Bacarisse
    Nov 30, 2006
  5. chris
    Replies:
    6
    Views:
    1,017
    chris
    Oct 28, 2005
Loading...

Share This Page