简体   繁体   中英

Stack overflow in VS multithreading

When I try to create a thread like this

someFunc(void* param){
char currFile[500000];
char currKeyBoard[24576];   
char currImage[500000]; 
char currAddInfo[12000];
}
_beginthread( someFunc, 0,NULL );

The program crash whith stackoverflow exception.But when I do this

    someFunc(void* param){
char currFile[500000];
char currKeyBoard[24576];   
char currImage[500000]; 
}
_beginthread( someFunc, 0,NULL );

the program don`t crash.Why?

The reason is the second function allocates less memory on the stack than the first. That is way too much stuff to allocate.

Use vectors instead, they'll allocate it on the heap, and since they manage their own memory you won't have to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM