Solved

beginthread and paging file size

Posted on 2000-04-04
4
327 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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
Thanks, you've answered to all my questions.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now