Solved

beginthread and paging file size

Posted on 2000-04-04
4
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 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.

732 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