|
I'd like to stress PJ's point that you should *always* use delete [] with new []. Otherwise strange things will happen. Trust me.
--
Schni Schna Schnappi! Schnappi Schnappi Schnapp!
|
|
|
|
|
|
I allways used delete regardless if used new or new[]
...it worked fine (and I see no reason why it should not...)
<br />
byte buffer[4] = new byte[4];
DWORD dw4Bytes = new DWORD[1];
<br />
...<br />
<br />
delete buffer;
delete dw4Bytes;
|
|
|
|
|
rubicon_hfr wrote:
...it worked fine (and I see no reason why it should not...)
Because for one thing, your example is not exception-safe. If in the "..." code an exception is thrown, you'll end up with a memory leak.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Because for one thing, your example is not exception-safe. If in the "..." code an exception is thrown, you'll end up with a memory leak.
Since the topic has the subject "about delete" I only mention that there is no difference between delete and delete[].
You may assume that "..." stands for the following:
<br />
try<br />
{<br />
}<br />
catch (...)<br />
{<br />
}<br />
Of course you can use finally to free memory...
Or you just use a wrapper class which ctor does this for you (so you can't forget)...
Or use managed C++
|
|
|
|
|
at least to an extent were its working took me 30min - 1hr to write it, had 1 bug but fixed it with debugging in under 3 sec. flat!!! so exciting but I came across a wierd error, when i just used "D3DXVECTOR3(x, y, 0)" in one of the location parameters in the ID3DXSPRITE interface, Draw() to be exact, it wouldn't accept it, but then i tried "&D3DXVECTOR3(x, y, 0)" and it worked, what am i misunderstanding here, D3DXVECTOR3 is type struct by the way
IM PROUD TO BE A GMAIL;
|
|
|
|
|
tom_dx wrote:
but then i tried "&D3DXVECTOR3(x, y, 0)" and it worked, what am i misunderstanding here, D3DXVECTOR3 is type struct by the way
Simple, a struct is completely different to a pointer.
tom_dx wrote:
IM PROUD TO BE A GMAIL;
So was I, until my mail started to disappear.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
whoops have to break out my C++ reference
IM PROUD TO BE A GMAIL;
|
|
|
|
|
I need something like Microsoft MonthView Control v6.0 (from mscomct2.ocx) but with the ability to select non-contiguous dates, too.
Thank you,
DC
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Thanks. It's hard to tell without a sample executable to play around with. Do you know if the dates can be navigated with the arrow keys on the keyboard?
- DC
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
I have working with CHtmlView derived SDI application.
Want to catch Event when user select print menu . do some processing like display a message box ..and then continuing printing ..How can I do it ..is it possible with OnCmdMsg() ..if yes How
|
|
|
|
|
Look for Virtual Function [CView::OnPreparePrinting]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi,
I am having real trouble getting this to work, basically I want to create an array of file names and folder names given a starting point, for example:
Start point:
C:\
Folder list:
Windows
Windows\Config
Windows\System32
Windows\System
File list:
Windows\appversions.dll
Windows\twain_32.dll
Windows\Config\foo.txt
Windows\System32\bootvrfy.exe
What would be the best way to go about this (Without using MFC), I have tried making a recursive method using FindFirstFile and FindNextFile but don't seem to be having any luck.
Thanks in advance!
|
|
|
|
|
__makaveli__ wrote:
I have tried making a recursive method using FindFirstFile and FindNextFile but don't seem to be having any luck.
Show us the code that is not working.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
void SearchFolders(LPCTSTR wStart)
{
WIN32_FIND_DATA hDat;
HANDLE hFindFile;
hFindFile = FindFirstFile(wStart, &hDat);
if( hFindFile != INVALID_HANDLE_VALUE ) {
while( FindNextFile(hFindFile, &hDat) )
{
if( hDat.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY ) {
// File is a folder
SearchFolders(hDat.cFileName);
} else {
// File is a file
MessageBox(0, hDat.cFileName, "File", MB_OK);
}
}
}
}
I have deleted the code that crashes but this was my last attempt, I tried to make it as simple as possible so I could expand on it once I got it showing a messagebox for each file but I do not get one messagebox.
|
|
|
|
|
Try changing
if( hDat.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY ) {
to
if( hDat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Thanks for the suggestion but still no messageboxes
|
|
|
|
|
Dont forget the wildcards:
SearchFolders("D:\\test\\*.*");
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I have just tried that, I am getting somewhere now, at first I got a stack of messageboxes all saying ".\*", I have now added a check for dots but it's still not recursive.
I'm now using:
void SearchFolders(LPCTSTR wStart)
{
WIN32_FIND_DATA hDat;
HANDLE hFindFile;
char DirSpec[MAX_PATH];
ZeroMemory(DirSpec, MAX_PATH);
strncpy (DirSpec, wStart, strlen(wStart+1));
strncat (DirSpec, "\\*", 3);
hFindFile = FindFirstFile(DirSpec, &hDat);
if( hFindFile != INVALID_HANDLE_VALUE ) {
while( FindNextFile(hFindFile, &hDat) )
{
if( hDat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
// File is a folder
if( (strncmp(hDat.cFileName, ".", 1) != 0) || (strncmp(hDat.cFileName, "..", 2) != 0 ) ) {
char subDir[MAX_PATH];
strcat(subDir, hDat.cFileName);
strcat(subDir, "\\*");
SearchFolders(subDir);
}
} else {
// File is a file
MessageBox(0, hDat.cFileName, "File", MB_OK);
}
}
}
}
|
|
|
|
|
__makaveli__ wrote:
strncat(DirSpec, "\\*", 3);
strncat(DirSpec, "\\*.*", 4); __makaveli__ wrote:
if( (strncmp(hDat.cFileName, ".", 1) != 0) || (strncmp(hDat.cFileName, "..", 2) != 0 ) ) {
char subDir[MAX_PATH];
strcat(subDir, hDat.cFileName);
strcat(subDir, "\\*");
SearchFolders(subDir);
The second condition is redundant (at least I've not ever seen a folder whose name began with a '.' but whose second character was not a '.'). Also, appending '*' here and at the start of the function is wrong.
if (hDat.cFileName[0] != '.')
{
char subDir[MAX_PATH];
strcpy(subDir, wStart);
strcat(subDir, "\\");
strcat(subDir, hDat.cFileName);
SearchFolders(subDir);
} See here and here for others' interpretation of this exercise. Here is an MFC snippet.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
DavidCrow wrote:
The second condition is redundant (at least I've not ever seen a folder whose name began with a '.' but whose second character was not a '.').
I have. The last time I used the CFile class from MFC, these names came up when I search through some folders...
Also when you use the dir command in dos, you see those names for the current and previous directory!
I also got the blogging virus..[^]
|
|
|
|
|
Bob Stanneveld wrote:
Also when you use the dir command in dos, you see those names for the current and previous directory!
That's exactly what I said. Unless a folder was named something like ".abc" I do not see the need to check the second character if the first one was a dot. It certainly does not hurt anything to check, but I was just trying to shorten the OP's code down a bit.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
__makaveli__ wrote:
SearchFolders(hDat.cFileName);
You'll need to append the previous directories to this path, and then call SearchFolders, or change your working directory before and after the call. The problem is that FindFirstFile is *always* searching the current directory.
|
|
|
|