why are you defining a buffer of 2000000000? Usually it's easier to allocate
memory and less resource intensive if you do that; defining a huge buffer like
that will quickly exhaust resources.
Thanks,
_|_|_|_|_| _| _|_|_|_|
_| _|_|_| _| _|_|_|
_| _| _| _|_|_| _|
_| _| _| _| _|
_| _| _| _|_|_|_| _|_|_|
Visit TDS for quality software and website production
http://tysdomain.com
msn: [EMAIL PROTECTED]
aim: st8amnd2005
skype: st8amnd127
----- Original Message -----
From: Thomas Hruska
To: [email protected]
Sent: Tuesday, September 09, 2008 6:59 PM
Subject: Re: [c-prog] Code Snippet Error
subhankar katyayan wrote:
> Dear All,
>
> Could you please look into the code snippet and let me know why it's giving
core and what should be the probable solution for this....
>
> #include <stdio.h>
>
> #define buffer_size 2000000000
> #define num_writers 300
> #define num_readers 500
>
> int main()
> {
> char *ptr;
> char *shmptr[num_writers];
> int i, numr, numw, nump;
>
> unsigned long cksum = 0;
>
> numr = nump % num_readers;
> numw = nump - numr;
> numw = numw / num_readers;
> ptr = shmptr[numw];
>
>
> for(i = 0; i < buffer_size; i++)
> cksum += *ptr++;
>
> }
>
> skumar
Among other things, 'nump' doesn't appear to be initialized. Your
compiler should be warning you about that. If not, turn up the warning
level until it does.
Also, a debugger would have caught what the compiler missed. Stepping
through the code will likely reveal that 'nump' gets assigned some
bizarre number.
Finally, your for-loop is likely going to step on some memory your
program isn't allowed to access for any reason whatsoever.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/
__________ NOD32 3429 (20080909) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
[Non-text portions of this message have been removed]