Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: making a unsigned char array gives a buffer overrun error Pin
Erudite_Eric7-Nov-11 20:53
Erudite_Eric7-Nov-11 20:53 
GeneralRe: making a unsigned char array gives a buffer overrun error Pin
User 5838527-Nov-11 21:14
User 5838527-Nov-11 21:14 
GeneralRe: making a unsigned char array gives a buffer overrun error Pin
Albert Holguin8-Nov-11 2:51
professionalAlbert Holguin8-Nov-11 2:51 
GeneralRe: making a unsigned char array gives a buffer overrun error Pin
Erudite_Eric7-Nov-11 7:45
Erudite_Eric7-Nov-11 7:45 
GeneralRe: making a unsigned char array gives a buffer overrun error Pin
Albert Holguin7-Nov-11 7:47
professionalAlbert Holguin7-Nov-11 7:47 
GeneralRe: making a unsigned char array gives a buffer overrun error Pin
Erudite_Eric7-Nov-11 8:10
Erudite_Eric7-Nov-11 8:10 
AnswerRe: making a unsigned char array gives a buffer overrun error Pin
Albert Holguin7-Nov-11 7:22
professionalAlbert Holguin7-Nov-11 7:22 
AnswerRe: making a unsigned char array gives a buffer overrun error Pin
Stefan_Lang10-Nov-11 2:24
Stefan_Lang10-Nov-11 2:24 
You said your app is dialog based, this also means that you have multiple threads, even though you may not be creating them manually. You can in fact allocate arrays of arbitrary size on the stack, but this is true only for the main thread. If you try to allocate on the stack of a thread, then this stack will be limited by the amount defined upon creation of that thread! If you do not create that thread yourself, or do not pass a stack size, then a default value will be assumed, and this value is probably smaller than what you wish to allocate.

The solution is to either
1. Allocate the array on the main thread and pass a pointer to it to the other thread, or
2. Allocate on the heap, rather than on the stack, or
3. Find out how to manually override the stack size of the thread in question (if that is even possible)

Having said that, the few answers I did bother to skim over seem to be mostly mistaken in their analysis and reasoning, even though some of the suggestions (such as allocating on the heap) might work.

Hope this helps.

P.S.: While I stated the stack of the main thread can be arbitrarily big, you still may have to tell the compiler this, via options, as Chuck already pointed out. I just tested on VS 2003 and VS 2010, and both define a default stacksize of 1 MB. I've found that, on a 12GB system I could increase the stack to 10GB and define an array of 1000 million doubles on the stack (in the main thread). (in VS, you can find that option under Linker/System/Stack Reserve Size)

modified 10-Nov-11 9:21am.

QuestionMFC DLL Won't Initialise Pin
Kyudos6-Nov-11 11:59
Kyudos6-Nov-11 11:59 
AnswerRe: MFC DLL Won't Initialise Pin
Albert Holguin6-Nov-11 13:08
professionalAlbert Holguin6-Nov-11 13:08 
GeneralRe: MFC DLL Won't Initialise Pin
Kyudos6-Nov-11 15:51
Kyudos6-Nov-11 15:51 
GeneralRe: MFC DLL Won't Initialise Pin
Albert Holguin7-Nov-11 7:12
professionalAlbert Holguin7-Nov-11 7:12 
AnswerRe: MFC DLL Won't Initialise Pin
Richard Andrew x647-Nov-11 12:38
professionalRichard Andrew x647-Nov-11 12:38 
GeneralRe: MFC DLL Won't Initialise Pin
Kyudos8-Nov-11 1:28
Kyudos8-Nov-11 1:28 
GeneralRe: MFC DLL Won't Initialise Pin
Richard Andrew x648-Nov-11 11:18
professionalRichard Andrew x648-Nov-11 11:18 
AnswerRe: MFC DLL Won't Initialise Pin
Kyudos21-Nov-11 16:06
Kyudos21-Nov-11 16:06 
QuestionProblem in Creating a directory Pin
Amrit Agr6-Nov-11 4:57
Amrit Agr6-Nov-11 4:57 
AnswerRe: Problem in Creating a directory Pin
André Kraak6-Nov-11 5:07
André Kraak6-Nov-11 5:07 
AnswerRe: Problem in Creating a directory Pin
Richard MacCutchan6-Nov-11 5:11
mveRichard MacCutchan6-Nov-11 5:11 
AnswerRe: Problem in Creating a directory Pin
User 74293386-Nov-11 6:34
professionalUser 74293386-Nov-11 6:34 
GeneralRe: Problem in Creating a directory Pin
Chuck O'Toole6-Nov-11 10:38
Chuck O'Toole6-Nov-11 10:38 
AnswerRe: Problem in Creating a directory Pin
«_Superman_»6-Nov-11 15:27
professional«_Superman_»6-Nov-11 15:27 
Questionupload a file from c++ using visual studio MFC to a php script Pin
carmaxuxo5-Nov-11 1:36
carmaxuxo5-Nov-11 1:36 
AnswerRe: upload a file from c++ using visual studio MFC to a php script Pin
Chuck O'Toole5-Nov-11 3:18
Chuck O'Toole5-Nov-11 3:18 
QuestionCan't clear Variant, debug help Pin
jkirkerx4-Nov-11 20:31
professionaljkirkerx4-Nov-11 20:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.