|
If you have implemented PrivateMalloc and PrivateFree, implementing new for your classes is a matter of overwriting new for each of them, or casting the memory in case of build-ins. I am just curios what does make your memory allocation superior to standard Windows algorithms? What is it you are gaining with custom memory management?
|
|
|
|
|
I don't want to add a new and delete to every class (although we could do this with a simple define and inline new/delete methods).
Our memory allocator (written about 12 years ago) is maybe not as advanced as some commercial memory allocators, but it does the following:
- handling memory pools in discrete sizes to prevent memory fragmentation
- showing memory leaks at the end of the application
- showing the stack of the malloc-location of leaks
- detecting memory overwrites
Especially the last 3 things are interesting, because we have the most interesting functionality of e.g. Rational Purify, but without the huge overhead (in cpu-time and in cost) of it.
Thanks for your answer anyway.
Enjoy life, this is not a rehearsal !!!
My Articles:
- Implementing a Subject/Observer pattern with templates
|
|
|
|
|
this is pretty much what MFC does in debug. You can try to adapt their approach.
1. Overload global new operator with some custom parameter
2. redefine new (see how MFC does it "#define DEBUG_NEW new(THIS_FILE, __LINE__)") to be redirected to your new
do not forget array new()[]. do the same for delete.
P.S. I would question the performance lose in your approach, but I guess it is worth it for you.
|
|
|
|
|
For your first and second points, I think I have the solution:
-- MemoryManager.h
#ifndef __MEMORYMANAGER_H__
#define __MEMORYMANAGER_H__
class MemoryManager
{
public:
MemoryManager()
{
if (m_uCount++ == 0)
{
}
}
~MemoryManager()
{
if (--m_uCount == 0)
{
}
}
private:
static UINT m_uCount;
};
static MemoryManager s_mm;
#endif
-- MemoryManager.cpp
#include "stdafx.h"
#include "MemoryManager.h"
UINT MemoryManager::m_uCount = 0;
Add your pool init/cleanup code inside MemoryManager's constructor/destructor and include MemoryManager.h inside all your CPPs. The static s_mm inside the header file ensures that your code is not called before or after it's appropriate.
Another approach to take is to look at the source code for MFC's memory tracking logic. If you purposely add a leak to your program, run it, and exit, it will report the leak at the end. You may want to take a look at files such as dbgheap.c to see how they accomplish this.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
Hello,
I got Platform SDK February 2001 edition from one of my friends.
I know it's older version now, i heard platform sdk 2003 is release now.
Anyway, i've problem in using platform sdk !
I've installed it in my system without any problem.
As i can see, platform sdk made some directories, for example Include - Lib - Src in installation directory.
How can i use them in my programs ?
Simply, by using Directories in Tools->Options ?
I'm scary about Confilcting files in vc directories ...
Any idea ?
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hadi Rezaee wrote:
I'm scary about Confilcting files in vc directories ...
Well, you simply need the D:\PlatFormSDK\include to be before (on top of) the MSVC++ ones. You do not delete them but keep them as a fallback.
And remember - they are from 1998 - extremely outdated. They only suppoert Win98, not even 98SE.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
1- Add include, src, lib directories to VC directories (Tools, Options, Directories)
2- VC searches header files and their implementations from that list. In other hand it searches first directory then seconde one and so on. When find desired file, using it for compiling. Because of this no conflicting will occured.
3- Find the latest PSDK from Microsoft.com
A. Riazi
|
|
|
|
|
I recently installed the May 2002 SDK just to have a look around and compare headers, test the tools, etc. It's a monster for a novice (as I am), but the Help documentation alone make the lengthy install worth it. Like the two previous posters, it's simple to set the directory paths in Visual C++ to the SDK include and library folders. There is a help page in the documentation that instructs you, in simple understandable language.
I tried it on a couple of simple programs that I'd put together for Windows 98, and usually it compiles correctly (as there are no significant changes in the headers). Then I tried it on a more complex programs written for Windows 2000, and I got (predictably) numerous error messages or, when it compiled, message boxes with error messages when launched. The new functions or altered parameters for old functions will operate incorrectly with the older Windows 98 Systems calls, and you will get those annoying message boxes with mysterious IDs and obscure functions.
However, it's worth the time to familiarize yourself with the process, and when you upgrade to a newer Windows version, the virtual chaos will not cause you undue mental distress and anguish.
|
|
|
|
|
Is it possible to create a file >2GB under NT/2K/XP
with normal Admin permisions.
I have tried:
CreateFile(...)
SetFilePointer(...)
but this fails with something like "permissions not correct"
please point me in the right direction
|
|
|
|
|
i dont think this is possible becz they allow a max partition of 2 gb and so i think that it is not possible to make a file size greater than that..anyway keep searching mayb u find a way thru..
cheers
himanshu
|
|
|
|
|
Did you use GENERAL_WRITE?
A. Riazi
|
|
|
|
|
'fraid so, did everything the online help system told me
code is below:
ULARGE_INTEGER i64FreeBytesToCallerC;
ULARGE_INTEGER i64TotalBytesC;
ULARGE_INTEGER i64FreeBytesC;
ULARGE_INTEGER i64FreeBytesToCallerD;
ULARGE_INTEGER i64TotalBytesD;
ULARGE_INTEGER i64FreeBytesD;
BOOL bSuccess = GetDiskFreeSpaceEx("C:\\",
(PULARGE_INTEGER)&i64FreeBytesToCallerC,
(PULARGE_INTEGER)&i64TotalBytesC,
(PULARGE_INTEGER)&i64FreeBytesC);
bSuccess = GetDiskFreeSpaceEx("D:\\",
(PULARGE_INTEGER)&i64FreeBytesToCallerD,
(PULARGE_INTEGER)&i64TotalBytesD,
(PULARGE_INTEGER)&i64FreeBytesD);
HANDLE hFile = ::CreateFile("C:\\File",GENERIC_WRITE|GENERIC_READ,
GENERIC_ALL,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
long dwHighPart = i64FreeBytesC.u.HighPart ;
DWORD result = ::SetFilePointer(hFile, i64FreeBytesC.u.LowPart, &dwHighPart, FILE_BEGIN);
|
|
|
|
|
You must (at least) take into account that creating a new file will probably allocate at least one cluster, and as the file grows it would probably need several more runs/clusters just to describe the layout of the file on disk.
Try reducing the size of the file you want to create, one page at a time, and I'm sure you'll see that sooner or later the SetFilePointer call will succeed.
Oh, another thing, be prepared that the process can, or more likely will hang for the duration of time needed to actually write NULL's to the filesize you requested (and it can't be terminated, not even by trying to kill it by Task Manager, since it's "hanging" in kernel-mode), why your machine could become "less useful" for other work in the time needed to zero-fill this file.
++luck;
|
|
|
|
|
Glynn wrote:
Is it possible to create a file >2GB under NT/2K/XP
with normal Admin permisions.
Absolutely. IIRC you can create files as large as 2^48 bytes (good luck finding any disks that large! ).
What you might experience is a problem with the filesystem? FATn have problems with large files (though I believe that error should only pop up around 4GB-1).
Maybe you just have a parameter problem for SetFilePointer?
Disk quota might be another thing that could limit you.
|
|
|
|
|
I want to force the update of the title of my application which appears in the taskbar.
I explain :
In my application (MFC), I have a Big Algorithm which take time. In the main loop of this Algorithm, I update the application name to display the percent. (The name look like : "MyAppli - 15%"). The Title of my application is correctly update by windows, but the Title of my application in the taskbar was not update until the end of the algorithm.
If I put a breakpoint in my algorithm, visual update the title in the taskbar... So I image, my algorithm use to CPU, to let the taskbar update itself.
I have try to add this code in the main loop when I change the title :
UInt32 ui32GotMsg;
MSG message;
SetWindowText( szPercent );
while (true)
{
ui32GotMsg = ::PeekMessage( &message, NULL, 0U, 0U, PM_REMOVE | PM_NOYIELD );
if (0 != ui32GotMsg)
{
::TranslateMessage( &message );
::DispatchMessage( &message );
}
else
{
break;
}
}
But, the title in the taskbar doesn't update... I have try to put the code
AfxGetApp->OnIdle(0) just after the 'SetWindowText()' but it doesn't work.
How I can do to force the update of the title of my application in taskbar ?
|
|
|
|
|
Change your code to this:
UInt32 ui32GotMsg;
MSG message;
while (true)
{
ui32GotMsg = ::PeekMessage( &message, NULL, 0U, 0U, PM_REMOVE | PM_NOYIELD);
if (ui32GotMsg != 0)
{
::TranslateMessage( &message );
::DispatchMessage( &message );
}
else
{
SetWindowText( szPercent );
}
}
I hope this works!
A. Riazi
|
|
|
|
|
I have try it, but it doesn't works. (And I must put a break after the SetWindowText( szPercent ); because I must give back CPU time to my algorithm.
My code seem like this :
void BigFunction()
{
for(i=0; i<ui32NbLoop; i++)
{
....
SetWindowsTile();
}
}
void SetWindowsTile()
{
while (true)
{
ui32GotMsg = ::PeekMessage( &message, NULL, 0U, 0U, PM_REMOVE | PM_NOYIELD);
if (ui32GotMsg != 0)
{
::TranslateMessage( &message );
::DispatchMessage( &message );
}
else
{
break;
}
}
}
|
|
|
|
|
Hi !!
I don't have any idea of how to do it, but here is something I'd like to do :
- Develop an app in C++, which would be portable for Windows and Linux.
- This app would have to interface a database (Oracle ? Any better database ?)
I would appreciate any hints on how to do it, or places where I could start searching.
Thanks !
Jerome
|
|
|
|
|
The following class libraries may help:
|
|
|
|
|
Thanks for the quick answer !
I'm sure I'll find plenty of usefull informations in the links you provided.
A question comes to my mind though...Is ODBC the only way to do it ? Or is it the easiest ? Does it exists on Linux ?
Thanks again for your help !
Jerome
|
|
|
|
|
ODBC is the most portable way, it exists in Linux/Unix and you can write database-independent code with it (with some effort).
|
|
|
|
|
If you know what DB you will use and you know it won't change, you can use the API of your DB. I think most of the known DBs have at least a C Interface you can use.
For Oracle look for OCI (Oracle Call Interface) in the Oracle-Docs (online at otn.oracle.com[^] )
<--edit-->
Forgot to mention Pro*C/C++ Precompiler for Oracle. With this precompiler you can write your SQL-Statemetns simply into your C/C++ code. Then run the precompiler. It will subsitute your statements with the correct OCI-calls.
<--edit-->
If you don't know what DB you will use or you want to be able to change it very easy you can use ODBC.
The hardest way: You can implement a generic Data-Access-Class in combination with a Wrapper-Class for each DB-API. So you just replace your wrapper class and you can use another DB.
--
karl
|
|
|
|
|
Thank you for your help, and for the link ! (and also for your suggestion about the hard-way....which I'll try to avoid !!!!)
Jerome
|
|
|
|
|
Hi,
I'm using SHBrowseForFolder Shell API, in my program to select a Folder. I have been able to Display only Drives by initializing a ITEMIDLIST got from SHGetSpecialFolderLocation, in the BROWSEINFO structure.
I dont want to display the Floppy Drive - Letter and the CD ROM Drive Letter. Also among the File System Drives, I want to only display drives (Drive Letters), that have a NTFS File System. Is there any way in which this can be done? i.e Can i filter out the drives that i dont want to display from the dialog that SHBrowseForFolder puts up?
Also can I use SHBrowseForFolder to display Drives and Folders from a Remote System?
Any information regarding this would be a great help.
Regards
Anand
|
|
|
|
|