Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

beginthread and paging file size

Posted on 2000-04-04
4
Medium Priority
?
344 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 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?
0
 
LVL 1

Author Comment

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

Featured Post

Technology Partners: 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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

721 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