Go Premium for a chance to win a PS4. Enter to Win


beginthread and paging file size

Posted on 2000-04-04
Medium Priority
Last Modified: 2010-04-02
I am using _beginthread in my program with a classical statement like:

_beginthread(start_func, 0, this);

where "start_func" is some static class member, and "this" points to another class from where beginthread is called. When I first compiled and ran the program (VC 6.0, Windows NT), my beginthread kept failing with error code 1455 - "insufficient paging file size". I had to TRIPLE the paging file size before this problem disappeared.

Why does it need so much space (virtual memory, I assume)? Is this anyhow related to the actual size of the class pointed by "this" that I am passing to the thread (even though I am passing a pointer) ??
Are there any other ways to minimize the amount of virt. memory required by a thread without inflating the paging files???
Question by:olegsp
  • 2
  • 2
LVL 22

Expert Comment

ID: 2685405
There is not inherent reason why starting a 2nd thread would need a lot of memory.  (bassically the only memory it needs is the space used for the stack, a minimal amount of spaces used by the OS to record ifo about the thread and a minimal amount of space used to store thread-specifc RTL info.)  So there must be something you are doing in your thread, or other parts of your program that is requiring this memory.  Like are you creating lots of local variables or large local varaibles?

There isn't much we can say to help you without knowing more about your program and this class.

Author Comment

ID: 2685491
Yeas, this might be the case, since I was copying some data into the thread to avoid potential sharing conflicts with the main application. As far as I know, a thread will allocate its own address space withing the address space of the main process, so (correct me if I am wrong)
1. If I pass a pointer to a thread, the thread will duplicate this pointer (32 bits) but not the object it points to?
2. If some object has global scope, and I use it in a thread, will it be replicated by the thread or not ?

I guess I am driving to "If I need to pass a lot of data to a thread, should I use pointers, global scope variables or anything else" ?
LVL 22

Accepted Solution

nietod earned 400 total points
ID: 2685834
>> As far as I know, a thread will allocate
>> its own address space withing
> the address space of the main process
No, there is 1 address space for all the threads in a process.  that means that all the threads can acess the same global variables.  it also means that they can acess the same dynamcially allocated memory (if a pointer to the memory is passed from one thread to another).

However each thread has its own stack, that means they have seperate local variables.  (one thread could access another thread's local varaibles, but only if the thread passed a pointer to a local variable to the other thread.

>>  If I pass a pointer to a thread, the thread
>> will duplicate this pointer (32 bits) but not
>> the object it points to?
Yes.  That is often a good thing, but it can be a bad thing at times.  For example, if thread A passes a pointer to a local variable to thread B and then the procedure in thread A that had the local varaible ends, the variable will be destroyed, but thread B might not "know" that   So in general this is only safe to do with global or dynamically allocated memory.  It can be done with locals, but with care.

>> 2. If some object has global scope, and I
>> use it in a thread, will it be replicated by the thread
>> or not ?
it will not, bit that single object will be shared among the threads.  That often means that access to the object must be syncronized using a mutex or critical section.  Are you familiar with this?  It is a very important topic that you MUSt understand if you program multiple threads.

>> "If I need to pass a lot of data to a thread,
>> should I use pointers, global scope
>> variables or anything else
It really depends on the circumstances.  but unless the data is increadibly large, this probably is not the source of the problem anyways.

Can you describe more about the program?

Author Comment

ID: 2688132
Thanks, you've answered to all my questions.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question