Allocation problem [message #909727] |
Fri, 07 September 2012 16:47 |
Jordi Jacobs Messages: 5 Registered: September 2012 |
Junior Member |
|
|
Hi,
I can't get this to work:
/*
============================================================================
Name : hello.c
Author :
Version :
Copyright :
Description : hello in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int var1[1000000];
printf("%i",var1[0]);
return EXIT_SUCCESS;
}
I see this:
http://www.eclipse.org/forums/index.php/t/255620/
"-Wl,--stack,2097152" does not seem to work...
How can I fix this?
(I do want that array on a bigger stack.)
[Updated on: Fri, 07 September 2012 22:22] Report message to a moderator
|
|
|
Re: Allocation problem [message #910021 is a reply to message #909727] |
Sat, 08 September 2012 11:50 |
Jordi Jacobs Messages: 5 Registered: September 2012 |
Junior Member |
|
|
Now i've done this in linux eclips-cdt:
code:
#include <stdlib.h>
#include <stdio.h>
#include <sys/resource.h>
int main(void)
{
const rlim_t kStackSize = 1024L * 1024L * 1024L;
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
printf("%i (%i)\n",(int)rl.rlim_cur,result);
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
printf("%i (%i)\n",(int)rl.rlim_cur,result);
result = getrlimit(RLIMIT_STACK, &rl);
printf("%i (%i)\n",(int)rl.rlim_cur,result);
int k[2090000];
printf("k\n");
return EXIT_SUCCESS;
}
output:
8388608 (0)
1073741824 (0)
1073741824 (0)
k
code2:
int k[2090000]; ==> int k[2099000];
Setting the RLIMIT_STACK to a bigger value does not seem to help...
Just to be sure: Each program has its own stack right? Because this linux command is throwing me off...
[Updated on: Sat, 08 September 2012 11:59] Report message to a moderator
|
|
|
Re: Allocation problem [message #910031 is a reply to message #910021] |
Sat, 08 September 2012 12:29 |
Jordi Jacobs Messages: 5 Registered: September 2012 |
Junior Member |
|
|
If I run the executable in a terminal I get this:
Segmentation fault (core dumped)
I like eclipse so far, but I don't like that it didn't show that error...
(Didn't find how to edit previous post...)
edit:
Lol that button was not there some seconds ago.
edit2:
valgrind gave this:
==7063== Process terminating with default action of signal 11 (SIGSEGV)
==7063== Access not within mapped region at address 0x7FE7FE3A8
==7063== at 0x400649: main (big_array.c:17)
==7063== If you believe this happened as a result of a stack
==7063== overflow in your program's main thread (unlikely but
==7063== possible), you can try to increase the size of the
==7063== main thread stack using the --main-stacksize= flag.
==7063== The main thread stack size used in this run was 8388608.
[Updated on: Sat, 08 September 2012 12:45] Report message to a moderator
|
|
|
|
Re: Allocation problem [message #910040 is a reply to message #910035] |
Sat, 08 September 2012 12:58 |
Jordi Jacobs Messages: 5 Registered: September 2012 |
Junior Member |
|
|
Thanks for pointing me to env limits.
Ow no lol that was not my intent, the k is random (bad case of random). That was just to show if the programm reaches that point or not, output on screen just shows a "k".
edit:
Could you be specific about the ulimts because I can't seem to get it to work...
btw
The first output seems to indicate that the limit-change has succeeded...
edit3:
when I take:
const rlim_t kStackSize = 16L * 1024L * 1024L;
instead of:
const rlim_t kStackSize = 1024L * 1024L * 1024L;
the problem persists...
Is there any other parameter that i need to change?
Maybe this is some virtual limit while the program is running into the real limit (stack-allocation)?
edit4:
valgrind gives a warning:
"Warning: client switching stacks? SP change: 0x7ff0000d0 --> 0x7fe7fe3d0
==8837== to suppress, use: --max-stackframe=8396032 or greater"
(edit5: this warning is just because of the large change in the stack pointer as expected and the guess "switching stacks" is wrong)
also:
the error occurs on the line after the allocation
"Access not within mapped region at address 0x7FE7FE3C8
==8837== at 0x40050C: main (big_array.c:32)"
line 32 being the next action
[Updated on: Sat, 08 September 2012 13:58] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.06456 seconds