Solved

beginthread and paging file size

Posted on 2000-04-04
4
332 Views
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???
0
Comment
Question by:olegsp
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 1

Author Comment

by:olegsp
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" ?
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 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?
0
 
LVL 1

Author Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 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