|
|
Hi, everyone!
Such is my view about memory release and allocate of
OS, that is, when a block of memory is marked unuse in
a process (maybe by free), it is not released to the system (OS) immediately.
On the contrary, when the number of the unused memory is
large enough, then all of the memory is released to system (OS).
Am I correct?
I still have a question. Suppose in a case, when process P has
freed a memory block M, but M has not released to system (OS)
yet. Then process P is going to allocate another memory
block. Can the new memory block use the space of memory clock M?
If it is so, I think it is more faster and efficient to use memory
this way than to allocate a memory block directly from memory.
Is that so?
Cheers,
George
|
|
|
|
|
the only bit i can contribute to, relates to the reuse of memory by the OS.
i have definitely come across Windows re-using a memory address immediately after that address was freed by delete.
at the time it really confused me because i was not resetting my previous pointer to null.
ie.
myob1* pOb1 = new myob1;
:
:
delete pOb1; // forgot to reset to null. doh!
myob2* pOb2 = new myob2; // pOb2 may share the same address as pOb1 did.
pOb1->somefunc(); // things go crazy here because the momory is valid but the object type is different.
|
|
|
|
|
Thanks, DanG pal!
I still have a question. In your example,
What is the difference between the two
statements?
1. delete pOb1;
2. pOb1=NULL;
A further question, if I want to set a pointer NULL,
need I delete it before I set it NULL?
Cheers,
George
|
|
|
|
|
pOb1=NULL will not free the memory => memory leak.
if the object was created using 'new' then at some point, some where, some code should call 'delete' on it else memory keeps on being allocated and not freed and the system will degrade until it crashes (if the momory leak is large enough).
i'm being a little vague on where or who does the de-allocation because this is a big subject in itself.
|
|
|
|
|
I've created an mfc-dll and everything works fine when invoked on my computer.
When we try it on another one, it fails and says that it can't find things like MFC...d.dll. I guess the d stands for dutch.
How can I compile and link that dll so it doesn't use those other anymore?
And another question: If we put the dll in the windows/system -directory, do we still have to provide the path to it when trying to load?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Grote Smurf (aka frisco) wrote:
When we try it on another one, it fails and says that it can't find things like MFC...d.dll. I guess the d stands for dutch.
The 'd' stands for debug.
You must distribute release builds and not debug builds.
Grote Smurf (aka frisco) wrote:
How can I compile and link that dll so it doesn't use those other anymore?
You can build it statically. Usually most people have the release MFC DLLs, but just in case...
Grote Smurf (aka frisco) wrote:
And another question: If we put the dll in the windows/system -directory, do we still have to provide the path to it when trying to load?
Nope, you don't have to!
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Verry quick response! Thanks
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Hi, everyone!
I have read some source codes about Trim and Mmap operation
of memory. But I still do not understand what means Trim and
Mmap opeartions of memory. Where can I find docuemnts about
details on what means Trim and Mmap?
Cheers,
George
|
|
|
|
|
I'm lost - neither of these are C++ keywords as far as I know. trim presumably trims, for example, a string to be a subset of what it was, but what does mmap stand for ? A multimap is an STL container, but I doubt that is what you're after.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Hi, Christian pal!
I am reading the source codes of a project that
deals with memory management. It can run both
on Windows and Linux. I just know that the two
functions are used to release unused memory back
to the system. But I do not know the details.
Do you know where can I find detailed document about
the two functions?
Have a nice day,
George
|
|
|
|
|
I implemented a base class CMyViewBase, there's a function CreateMyChild(xxxxx ... ) which has to put in a CWnd * as the parent.
However, it can only be known in the derived class only, such that my classes are derived from CTabCtrl, CView also. How can a child know that ??
Can my derived class using "virtual" CMyViewBase in declare inheritance, and my base class using public CWnd ?
|
|
|
|
|
Sorry about this, does anyone know what the following code does
<br />
<br />
DWORD Thing::GetDiviceFreeSpace(LPCTSTR lpszPath)<br />
{<br />
struct statfs sStats;<br />
if(statfs(lpszPath,&sStats)== -1)<br />
return 0;<br />
return sStats.f_bsize * sStats.f_bavail;<br />
<br />
}<br />
I found it in some project I am working on, confusing
---
Why are all the good signitures taken already?
|
|
|
|
|
You need to know what the struct is in order to know what it does. the statfs struct must be defined somewhere else for this to do anything. Search MSDN, if it's not there, search your code.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Is the code from an Unix/Linux program? statfs() appears to be a Linux or BSD Unix syscall, on Linux the documentation says:
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);
DESCRIPTION
statfs returns information about a mounted file system. path is the
path name of any file within the mounted filesystem. buf is a pointer
to a statfs structure defined as follows:
struct statfs {
long f_type;
long f_bsize;
long f_blocks;
long f_bfree;
long f_bavail;
long f_files;
long f_ffree;
fsid_t f_fsid;
long f_namelen;
long f_spare[6];
};
|
|
|
|
|
Coremn wrote:
Sorry about this, does anyone know what the following code does
DWORD Thing::GetDiviceFreeSpace(LPCTSTR lpszPath)<br /> may very well get a devices free space.
statfs() sounds very much like "STATatus of FileSystem", so this would also fit in.
Third, a search in MSDN showed statfs() to be a "NFS Version 2 RPC Call", the description being 'Get file system attributes'.
Hope this helped
PS. I charge you 30 Dollar for information retrieval service.
|
|
|
|
|
Thanks dudes - it will help
The cheque is in the mail.
---
|
|
|
|
|
Hello all,
Is there anyway to access C++ Library by using Java (Pure Java)? If yes, please give me some instructions.
Thank you very much.
Long Truong
|
|
|
|
|
Aren't you a little bit offtopic here ?
Try this one.
God luck,
And I swallow a small raisin.
|
|
|
|
|
I know that CRichEditCtrl::SetSel(0,-1) will select all text in richedit control. But I don't understand about GetSel(). When I call CRichEditCtrl::GetSel(nStart, nEnd) to get selection range (after I called CRichEditCtrl::SetSel(0,-1)). Why the range is greater than text length.
Example:
- current text is "Hello". (text length = 5)
- then I call CRichEditCtrl::SetSel(0,-1).
- and then I call CRichEditCtrl::GetSel(nStart, nEnd).
- the result is nStart=0 and nEnd=7.
?? Why nEnd is not equal 5? What is the two addition?
|
|
|
|
|
maybe its a 'carriage return\linefeed' pair on the end.
|
|
|
|
|
I have the following encapsulation of a CriticalSection and Lock (out of my school textbook)
class Mutex
{
friend class Lock;
public:
Mutex () { InitializeCriticalSection (& _critSection); }
~Mutex () { DeleteCriticalSection (& _critSection); }
private:
void Acquire ()
{
EnterCriticalSection (& _critSection);
}
void Release ()
{
LeaveCriticalSection (& _critSection);
}
CRITICAL_SECTION _critSection;
};
class Lock
{
public:
// Acquire the state of the semaphore
Lock ( Mutex & mutex )
: _mutex(mutex)
{
_mutex.Acquire();
}
// Release the state of the semaphore
~Lock ()
{
_mutex.Release();
}
private:
Mutex & _mutex;
};
In the mutex class, why is the private member stored by reference? That is the line Mutex & _mutex;
I am asking, coz I used the classes for a school project and missed the &. My program crashed windows and it took me 6 hours to find the missing &! Why is it necessary to store it by reference?
Pankaj
Without struggle, there is no progress
|
|
|
|
|
when you pass an object by value, a copy of the object is created and passed to the function. this object will go out of scope and its destructor will be called, when the function exits.
when you pass by reference, the function uses the original object (via a pointer) and, so the object doesn't go out of scope when the function exits (and the destructor is not called).
a quick glance at your code...
the Mutex destructor deletes the critical section, possibly while some code is using it.
-c
Argue for your limitations, and sure enough, they're yours.
|
|
|
|
|
You should probably add a flag to your Mutex class indicating whether or not the cs has been acquired:
<br />
void Acquire ()<br />
{<br />
if (!bAcquired) <br />
EnterCriticalSection (& _critSection);<br />
else<br />
assert(!"Something is fishy!");<br />
bAcquired = true;<br />
}<br />
<br />
void Release ()<br />
{<br />
if (bAcquired)<br />
LeaveCriticalSection (& _critSection);<br />
else<br />
assert(!"Something is fishy!");<br />
bAcquired = false;<br />
}<br />
Todd Smith
|
|
|
|
|
Build output message "Build : warning : failed to (or don't know how to) build 'D:\SFS\Debug\NMSV3r1.pch'"
I already configure my project correctly, and rebuild all the project,
but still can't complile my project, why?
thanks.
|
|
|
|