|
I had some trouble with my app because it allocates a lot of memory. The longer you use it the more memory was eaten away. After searching for a reason I endet up with CFindFile as the only reason for that.
I have a loop and after deleting all but the CFileFind calls it is the only think that keeps running and allocating memory. Unfortunately CFileFind seems to not release the memory it uses. I tried everything:
CFindFile* findfile=new CFindFile();<br />
findfile->Close();<br />
delete findfile;
doesn't release any of the allocated memory. Can someone help me? How can I free the allocated memory. Is there a alternate way to search for files in a directory?
|
|
|
|
|
There is no reason to use a heap variable here. Use a stack variable and your memory-related problems will stop.
ryuki wrote:
doesn't release any of the allocated memory.
Actually it does, but you are confused as to what happens with memory once it is freed. If you are using Task Manager to watch your program's memory drop after each call to free , you will surely be disappointed.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I work under Win98 and use the systemmonitor for viewing allocated memory. Its not easy to say but there seems to be more to the memory issue than expected. I managed to find another source of consuming memory. It is a little part including SHGetFileInfo. And that small codebit causes much more trouble than all other together. It seems that SHGetFileInfo allocates memory too. But you can't see it at the systemmonitor. It eats all of it with time and at a single point I can't create threads anymore or some functions like StretchDIBits doesn't work properly because there is no memory anymore. I get a lot of "Not enough memory" errors allthough all ressourceviewers say there are more than 100 MB of free memory still there.
I can give you the small code example:
<br />
SHFILEINFO sfi;<br />
UINT uFlags = SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON;<br />
if ( SHGetFileInfo ( tmp, 0, &sfi, sizeof(SHFILEINFO), uFlags ))<br />
m_ctrPathFrom->InsertItem ( npos, sfi.szDisplayName, sfi.iIcon );<br />
Thats all. I looked at the documentation but it says nothing about freeing the structure or something. Does someone know what to do?
And you can be believe me, i traced the cause of the memory issue to that single if-line.
I hope someone can help.
|
|
|
|
|
From MSDN:
[quote]
Remarks
If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it.
[/quote]
sig test
|
|
|
|
|
Thank you for the hint. I use the standart documentation, the msdn library coming with VC++ 6. Next Time I will check the online docu too.
|
|
|
|
|
ryuki wrote:
...the msdn library coming with VC++ 6.
Which is nearly five years old.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I am a little new to the thread world and was wondering if someone can provide some assistance to get me started in a file monitoring project. Here is what i am attempting to accomplish:
From a win 32 dll, monitor a particular directory constantly for new files. Everytime a new file gets put in there, this thread or something will detect this, open the file and read from it. Once done reading, it will store it in another directory and move onto looking to see if another file got placed in that directory.
I was thinking that in the dll, i can run a thread that will monitor the directory and perform the functionality above.
Firstly, does it make sense to use a thread in this case, and secondly, can anyone provide some guidance or sample code to get me started?
Thanks in advance.
|
|
|
|
|
you can't just do it like this!!
It takes time to write a file -> it may happen that you detect a new file when it is not yet completly written!
What exactly do you want to do? Which software does create the files? What kind of files? ...
Don't try it, just do it!
|
|
|
|
|
If the other progrma is under your control, you would need to make sure it opened the file for exclusive readn and write access, so that the file monitor could not access the file until the 'original' author was finished.
This would partially solve the problem.
|
|
|
|
|
It is a third party software that is creating the files. I can assume that the files will be saved off to a known directory at any time.
These files are XML files. Even if it takes 1 hour for the file to be written to the directory that is fine. I just have to monitor the directory it so that when it does get written, i can load it and parse through xml parser for what i need.
|
|
|
|
|
Look at FindFirstChangeNotification . I am pretty sure there are some samples on CodeProejct for this API. Yes, it is the kind ofperation I would place into a thread, since you have to use the Wait... functions to wait for changes to occur. Not the kind of operation I would want blocking the primary thread of my program.
|
|
|
|
|
Thanx, i will try this and let you know how it works.
|
|
|
|
|
Also check out ReadDirectoryChangesW() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I use a win32 dll to read an XML document. CString is not an option. I read one particular tag and i have to store the contents of that tag in a variable and then parse it to extarct certain data and store elsewhere.
My first question is :
MSXML2::IXMLDOMNodePtr ptagNode;
sometype strvar = ptagNode->text;
What "type" should sometype be? I am using a _bstr_t but i do not know how to exactly use functions to search this if there are any at all, cause i haven't seen any. Can anyone advise me as to what type i should use that will allow me to easily parse the data since i cannot use CString? I would like to use methods such as find to find a substring etc.
Thanks..
|
|
|
|
|
LCI wrote:
What "type" should sometype be?
std::string
it's a little non-intuitive, at first. and a lot of functionality you might expect doesn't exist. but it's pretty simple to add what you need, in most cases.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
if i use std::string and i declare strVar as a string, i get undeclared identifier. Is there something else that i am missing? I also did a #include <string.h>
Help!
|
|
|
|
|
#include < string >
..
std::string strVar;
strVar = "hi";
or
#include < string >
using namepsace std;
..
string strVar;
strVar = "hi";
most will recommend the former.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
I have a .h and a .lib file that I can use in a Win32 C++ Console application. I like to use it in a .NET C# program is that possible. Suggestions on articles in this topic would be great!
_____________________________
...and justice for all
APe
|
|
|
|
|
Yes it's possible, BUT you have to create a c++ dll from the lib file.
Use a def file for the dll to export some functions from the lib (for C exports), or, change the header file with the class attributes __declspec(dllexport) to export classes.
Don't try it, just do it!
|
|
|
|
|
Ok.
Unfoutanly my the .h-file is about 50.000 lines of code and the lib is about 40MB. Does it exist any tool for accomplish this?
By the way, is it possible to export a class for use in C#?
_____________________________
...and justice for all
APe
|
|
|
|
|
Hello
Can anyone tell me that how can i search out the specific string in a text file.and then change it
|
|
|
|
|
How you search for a string really depends on how you are processing the file. If the file was opened as a CStdioFile object, you can use the ReadString() method to read one line at a time from the file. That line of text can then be searched for the string of interest.
Once you have this bit working, create another post and we can give you suggestions on replacing text.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
where can i get the simplest example ?
vivek
|
|
|
|
|
You can make use of the ADO wrapper classes from Carlos Antonelli here at codeproject in the Database section. The usage is same as the MFC DAO classes. Great work.
MS
|
|
|
|