|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
execution error if large buffer |
« View previous topic :: View next topic » |
Author |
Message
|
sebastia |
Posted: Fri Dec 27, 2013 8:06 am Post subject: execution error if large buffer |
|
|
 Grand Master
Joined: 07 Oct 2004 Posts: 1003
|
Hi, coleagues. I have a strange compile/runtime problem.
Under XP and using MQ 7.5 I have these lines in a CMD to compile :
Code: |
echo "1 - set Visual Studio envir"
CALL "c:\MVS\VC98\Bin\VCVARS32.BAT"
echo "2 - compile"
CL amqsecha.c -o AMQSECHA.EXE mqm.lib |
The program I am working with is AMQSECHA and the problematic lines are
Code: |
#define MaxMsgLng 1024*1024*4
MQBYTE buffer[ MaxMsgLng ] ; /* message buffer */ |
If the buffer size is 1MB or more, there is no compile error, but program crashes at start. XP says "AMQSECHA.EXE has encoutered a problem and needs to close."
If buffer is 900 KB, all runs ok.
Do you have any idea of what am I doing wrong ?
Any compiler flag ?
Sebastian. |
|
Back to top |
|
 |
PaulClarke |
Posted: Sun Dec 29, 2013 8:12 am Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
The way AMQSECHA is coded is that the buffer variable is defined on the stack. This is fine for small amounts of data, such as 100 bytes in the original code but it's not really a good idea to have large amounts of data on the stack. In your case you are trying to define a variable of 4MB on the stack. If I remember correctly the default stack size for a Visual Studio program is only 1MB so I'm not hugely surprised that such a large variable causes problem (although I am a little surprised that the failure isn't more graceful). What I suggest you do is change the code so that the buffer is allocate on the heap....
Something like.....
MQLONG MaxMsgSize = 4 * 1024 * 1024;
char * buffer;
buffer = malloc(MaxMsgSize);
Of course you will also have to change the line...
buflen = sizeof(buffer) - 1;
to
buflen = MaxMsgSize - 1;
Hope this helps,
Paul. _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
sebastia |
Posted: Sun Dec 29, 2013 8:31 am Post subject: |
|
|
 Grand Master
Joined: 07 Oct 2004 Posts: 1003
|
Thanks Paul.
In fact a 1 MB buffer also crashes the program, so your explanation looks correct to me.
Yes, I am also very surprised there is no "warning" somewhere.
Thanks for your coding improvement. Shall use it tomorrow, jejeje.
Cheers & Happy 2014.
Sebastian. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|