* memory allocation
@ 1999-11-04 2:15 Anand Ganesh
1999-11-04 3:00 ` Martin Kahlert
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Anand Ganesh @ 1999-11-04 2:15 UTC (permalink / raw)
To: help-gcc
Hi,
Why doesnt gcc crib when I make an array declaration that it cant
handle ?
eg
float array[10000][5][5];
That there is a problem I realised b'cos some unrelated variables were
getting changed. The reason I declared such an array instead of mallocing
is that it is easier to pass 3D arrays rather than float*** which you cant
use as a 3D array anymore (since dimensions are not known).
Is there a way to get a warning from gcc ? (I did gcc -Wall)
Thanks in advance for any help,
ag.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: memory allocation
1999-11-04 2:15 memory allocation Anand Ganesh
@ 1999-11-04 3:00 ` Martin Kahlert
1999-11-30 23:28 ` Martin Kahlert
1999-11-04 6:16 ` Arthur Gold
1999-11-30 23:28 ` Anand Ganesh
2 siblings, 1 reply; 11+ messages in thread
From: Martin Kahlert @ 1999-11-04 3:00 UTC (permalink / raw)
To: help-gcc
In article < Pine.SGI.4.10.9911040409470.31041-100000@whirlwind.cs.utexas.edu >,
Anand Ganesh <anandg@cs.utexas.edu> writes:
> Hi,
> Why doesnt gcc crib when I make an array declaration that it cant
> handle ?
> eg
> float array[10000][5][5];
>
> That there is a problem I realised b'cos some unrelated variables were
> getting changed. The reason I declared such an array instead of mallocing
> is that it is easier to pass 3D arrays rather than float*** which you cant
> use as a 3D array anymore (since dimensions are not known).
Then you will probably do out of bound writes inside your code.
array is just 5*5*10000*4=1MB in size.
There shouldn't be any problem with that.
If you get a segfault, then try the shell command limit
(i assume you are on Unix-shells here)
Hope, that helps,
Martin.
--
The early bird gets the worm. If you want something else for
breakfast, get up later.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: memory allocation
1999-11-04 3:00 ` Martin Kahlert
@ 1999-11-30 23:28 ` Martin Kahlert
0 siblings, 0 replies; 11+ messages in thread
From: Martin Kahlert @ 1999-11-30 23:28 UTC (permalink / raw)
To: help-gcc
In article < Pine.SGI.4.10.9911040409470.31041-100000@whirlwind.cs.utexas.edu >,
Anand Ganesh <anandg@cs.utexas.edu> writes:
> Hi,
> Why doesnt gcc crib when I make an array declaration that it cant
> handle ?
> eg
> float array[10000][5][5];
>
> That there is a problem I realised b'cos some unrelated variables were
> getting changed. The reason I declared such an array instead of mallocing
> is that it is easier to pass 3D arrays rather than float*** which you cant
> use as a 3D array anymore (since dimensions are not known).
Then you will probably do out of bound writes inside your code.
array is just 5*5*10000*4=1MB in size.
There shouldn't be any problem with that.
If you get a segfault, then try the shell command limit
(i assume you are on Unix-shells here)
Hope, that helps,
Martin.
--
The early bird gets the worm. If you want something else for
breakfast, get up later.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: memory allocation
1999-11-04 2:15 memory allocation Anand Ganesh
1999-11-04 3:00 ` Martin Kahlert
@ 1999-11-04 6:16 ` Arthur Gold
1999-11-05 14:01 ` Anand Ganesh
1999-11-30 23:28 ` Arthur Gold
1999-11-30 23:28 ` Anand Ganesh
2 siblings, 2 replies; 11+ messages in thread
From: Arthur Gold @ 1999-11-04 6:16 UTC (permalink / raw)
To: help-gcc
What do you mean by "can't handle"?
I suspect there's something else going on in your code.
Have you run your program through gdb?
HTH,
--ag
Anand Ganesh wrote:
>
> Hi,
> Why doesnt gcc crib when I make an array declaration that it cant
> handle ?
> eg
> float array[10000][5][5];
>
> That there is a problem I realised b'cos some unrelated variables were
> getting changed. The reason I declared such an array instead of mallocing
> is that it is easier to pass 3D arrays rather than float*** which you cant
> use as a 3D array anymore (since dimensions are not known).
>
> Is there a way to get a warning from gcc ? (I did gcc -Wall)
>
> Thanks in advance for any help,
> ag.
>
>
--
Artie Gold, Austin, TX
mailto:agold@bga.com or mailto:agold@cs.utexas.edu
--
"If you come to a fork in the road, take it." L. P. Berra
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: memory allocation
1999-11-04 6:16 ` Arthur Gold
@ 1999-11-05 14:01 ` Anand Ganesh
1999-11-30 23:28 ` Anand Ganesh
1999-11-30 23:28 ` Arthur Gold
1 sibling, 1 reply; 11+ messages in thread
From: Anand Ganesh @ 1999-11-05 14:01 UTC (permalink / raw)
To: help-gcc
On Thu, 4 Nov 1999, Arthur Gold wrote:
> What do you mean by "can't handle"?
> I suspect there's something else going on in your code.
- I mean that enough memory is not allocated (b'cos it's not available ?)
for the array
>
> Have you run your program through gdb?
- yes I have
Fact is I had other arrays which were not just arrays of floats -
but arrays of large structs. I figured that each array was 4-5M and I
had about 5-6 of them strewn all over the code. That was causing the
trouble. I had declared them statically (not malloc ie). Shouldnt gcc warn
me that things are likely to go wrong ? The program works now that I
shifted to pointers and use malloc instead.
- is there a way to malloc a 3D array ? - or do I have to do it in 3
stages ?
-regarding Martin's response - no I was not exceeding array bounds - since
the program works now :-)
Thanks,
ag.
<
I changed a struct Big big[10000]; to
struct Big* big;
big = (struct Big*)malloc(10000*sizeof(struct Big));
and then things worked.
>
> HTH,
> --ag
>
> Anand Ganesh wrote:
> >
> > Hi,
> > Why doesnt gcc crib when I make an array declaration that it cant
> > handle ?
> > eg
> > float array[10000][5][5];
> >
> > That there is a problem I realised b'cos some unrelated variables were
> > getting changed. The reason I declared such an array instead of mallocing
> > is that it is easier to pass 3D arrays rather than float*** which you cant
> > use as a 3D array anymore (since dimensions are not known).
> >
> > Is there a way to get a warning from gcc ? (I did gcc -Wall)
> >
> > Thanks in advance for any help,
> > ag.
> >
> >
>
> --
> Artie Gold, Austin, TX
> mailto:agold@bga.com or mailto:agold@cs.utexas.edu
> --
> "If you come to a fork in the road, take it." L. P. Berra
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: memory allocation
1999-11-05 14:01 ` Anand Ganesh
@ 1999-11-30 23:28 ` Anand Ganesh
0 siblings, 0 replies; 11+ messages in thread
From: Anand Ganesh @ 1999-11-30 23:28 UTC (permalink / raw)
To: help-gcc
On Thu, 4 Nov 1999, Arthur Gold wrote:
> What do you mean by "can't handle"?
> I suspect there's something else going on in your code.
- I mean that enough memory is not allocated (b'cos it's not available ?)
for the array
>
> Have you run your program through gdb?
- yes I have
Fact is I had other arrays which were not just arrays of floats -
but arrays of large structs. I figured that each array was 4-5M and I
had about 5-6 of them strewn all over the code. That was causing the
trouble. I had declared them statically (not malloc ie). Shouldnt gcc warn
me that things are likely to go wrong ? The program works now that I
shifted to pointers and use malloc instead.
- is there a way to malloc a 3D array ? - or do I have to do it in 3
stages ?
-regarding Martin's response - no I was not exceeding array bounds - since
the program works now :-)
Thanks,
ag.
<
I changed a struct Big big[10000]; to
struct Big* big;
big = (struct Big*)malloc(10000*sizeof(struct Big));
and then things worked.
>
> HTH,
> --ag
>
> Anand Ganesh wrote:
> >
> > Hi,
> > Why doesnt gcc crib when I make an array declaration that it cant
> > handle ?
> > eg
> > float array[10000][5][5];
> >
> > That there is a problem I realised b'cos some unrelated variables were
> > getting changed. The reason I declared such an array instead of mallocing
> > is that it is easier to pass 3D arrays rather than float*** which you cant
> > use as a 3D array anymore (since dimensions are not known).
> >
> > Is there a way to get a warning from gcc ? (I did gcc -Wall)
> >
> > Thanks in advance for any help,
> > ag.
> >
> >
>
> --
> Artie Gold, Austin, TX
> mailto:agold@bga.com or mailto:agold@cs.utexas.edu
> --
> "If you come to a fork in the road, take it." L. P. Berra
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: memory allocation
1999-11-04 6:16 ` Arthur Gold
1999-11-05 14:01 ` Anand Ganesh
@ 1999-11-30 23:28 ` Arthur Gold
1 sibling, 0 replies; 11+ messages in thread
From: Arthur Gold @ 1999-11-30 23:28 UTC (permalink / raw)
To: help-gcc
What do you mean by "can't handle"?
I suspect there's something else going on in your code.
Have you run your program through gdb?
HTH,
--ag
Anand Ganesh wrote:
>
> Hi,
> Why doesnt gcc crib when I make an array declaration that it cant
> handle ?
> eg
> float array[10000][5][5];
>
> That there is a problem I realised b'cos some unrelated variables were
> getting changed. The reason I declared such an array instead of mallocing
> is that it is easier to pass 3D arrays rather than float*** which you cant
> use as a 3D array anymore (since dimensions are not known).
>
> Is there a way to get a warning from gcc ? (I did gcc -Wall)
>
> Thanks in advance for any help,
> ag.
>
>
--
Artie Gold, Austin, TX
mailto:agold@bga.com or mailto:agold@cs.utexas.edu
--
"If you come to a fork in the road, take it." L. P. Berra
^ permalink raw reply [flat|nested] 11+ messages in thread
* memory allocation
1999-11-04 2:15 memory allocation Anand Ganesh
1999-11-04 3:00 ` Martin Kahlert
1999-11-04 6:16 ` Arthur Gold
@ 1999-11-30 23:28 ` Anand Ganesh
2 siblings, 0 replies; 11+ messages in thread
From: Anand Ganesh @ 1999-11-30 23:28 UTC (permalink / raw)
To: help-gcc
Hi,
Why doesnt gcc crib when I make an array declaration that it cant
handle ?
eg
float array[10000][5][5];
That there is a problem I realised b'cos some unrelated variables were
getting changed. The reason I declared such an array instead of mallocing
is that it is easier to pass 3D arrays rather than float*** which you cant
use as a 3D array anymore (since dimensions are not known).
Is there a way to get a warning from gcc ? (I did gcc -Wall)
Thanks in advance for any help,
ag.
^ permalink raw reply [flat|nested] 11+ messages in thread
* re: memory allocation
@ 2003-09-13 15:00 Dan Kegel
0 siblings, 0 replies; 11+ messages in thread
From: Dan Kegel @ 2003-09-13 15:00 UTC (permalink / raw)
To: GCC Mailing List, gcc-help, laczo.tibor
Laczó Tibor wrote:
[ In Redhat Linux, how come calling delete on objects in C++
doesn't return memory to the operating system? Even after
my program deletes all its big objects, RSS doesn't shrink. ]
That's an FAQ. http://www.lysator.liu.se/c/c-faq/c-3.html says
Q. I have a program which mallocs but then frees a lot of memory,
but memory usage (as reported by ps) doesn't seem to go back down.
A. Most implementations of malloc/free do not return freed memory to
the operating system (if there is one), but merely make it available
for future malloc calls within the same process.
glibc's manual also mentions this:
http://www.gnu.org/manual/glibc-2.2.5/html_node/Freeing-after-Malloc.html#Freeing%20after%20Malloc
which says
"Occasionally, free can actually return memory to the operating system
and make the process smaller. Usually, all it can do is allow a
later call to malloc to reuse the space. In the meantime,
the space remains in your program as part of a free-list used internally by malloc."
Please take this discussion to gcc-help@gcc.gnu.org
or maybe comp.lang.c++.
gcc@gcc.gnu.org is for gcc maintainers, not users.
- Dan
--
Dan Kegel
http://www.kegel.com
http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=78045
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <CANEcUBX9ntHdZ7qEJg7ke=MADcxfP_uOwNnA==XvKbf3kyH1Lw@mail.gmail.com>]
end of thread, other threads:[~2013-09-19 2:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-04 2:15 memory allocation Anand Ganesh
1999-11-04 3:00 ` Martin Kahlert
1999-11-30 23:28 ` Martin Kahlert
1999-11-04 6:16 ` Arthur Gold
1999-11-05 14:01 ` Anand Ganesh
1999-11-30 23:28 ` Anand Ganesh
1999-11-30 23:28 ` Arthur Gold
1999-11-30 23:28 ` Anand Ganesh
2003-09-13 15:00 Dan Kegel
[not found] <CANEcUBX9ntHdZ7qEJg7ke=MADcxfP_uOwNnA==XvKbf3kyH1Lw@mail.gmail.com>
[not found] ` <CAKOQZ8zsfKUFv0PDhUmDWDgqD9p-xMYUfW_eR9B-TWx5yjmjeQ@mail.gmail.com>
2013-09-19 1:04 ` zhaobin xv
2013-09-19 2:38 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).