|
Using new and delete [] or GlobalAlloc will work but it is operating at an unnecessarily low level. Standard C++ has a container called a vector which will suit your needs and has many advantages including the fact that it automatically frees memory saving you from the burden of remembering to call delete [] .
To use it first include its header file like this:
#include <vector>
Now you can whip up a vector of float s like this:
std::vector<float> YourVectorOfFloats
Now you can use this as before but you don't need to call delete [] and it has lots of member functions that you can use.
For example, you want to expand it? No worries:
YourVectorOfFloats.resize(400);
Unless he has highly specialized needs there is no good reason for a C++ programmer to use new and delete [] or Win32 APIs such as GlobalAlloc to make dynamic arrays - In general it is a mistake to do so.
Steve
|
|
|
|
|
Thanks Steve, I will implement it.
|
|
|
|
|
I have a very large VC++ (Visual Studio 2003) Win32 console application who's memory grows at a steady rate over time. I've tried:
* DevPartner BoundsChecker - System runs out of memory when application is running from BoundsChecker (we use a lot of memory and have lots of allocations)
* umdh - This free tool from Microsoft can't handle the number of allocatino we do, so we can get one, maybe two, tests run before this tool stops giving data.
* Purify - This tool worked to some degree, but also had limitations on how many test iterations it would handle.
* HeapAgent - Just downloaded it.
Any suggestions on tools that can handle a really big application?
Barry Etter
|
|
|
|
|
try to scope down your problem, if there is some point in your program that you can actually "stop" doing something ( by putting some code in comment, for example ) do it, see if it helps those tools.
try to implement some unit tests to see if those can be used to find the memory leaks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Start with this:
http://www.codeproject.com/tools/leakfinder.asp[^]
Customize to fit your needs. As Max said, you'll want to cut down the scope to where it is manageable. A good way to do this is to identify operations that *shouldn't* leave memory allocated, and wrap them in checks. Starting with the larger operations and narrowing scope should let you zone in on the problem fairly quickly.
Oh, and i should also mention this tool:
http://www.softwareverify.com/memoryValidator/index.html[^]
I've found it to be a good deal faster than BoundsChecker, and it also has the ability to start and stop data collection, which can be quite nice when you want to ignore initial allocations.
|
|
|
|
|
One thing I've done with BoundsChecker in similar situations is to limit the source files that were instrumented.
For what it's worth, I've tried HeapAgent in the past and hated it. Your mileage may vary.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Could you tell me : How to get my IP address ???
What's happened if my computer don't connect to the Internet or LAN, or i don't install IIS ???
And:
If i connect over LAN,
how to get other Computer name if i know its IP
and how to get other computer's IP if i know its name ?
|
|
|
|
|
Surivevoli wrote: How to get my IP address ???
On windows: Open the dos command prompt and type: ipconfig
Then type enter, and your ip address will come up.
Surivevoli wrote: And:
If i connect over LAN,
how to get other Computer name if i know its IP
and how to get other computer's IP if i know its name ?
What OS are you running?
|
|
|
|
|
oh,my God!
I want get it from C/MFC code !!!
could you tell me ???
|
|
|
|
|
|
You've made my day...
Nibu thomas
Software Developer
|
|
|
|
|
See here.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
I have created the file open/save dialog box using CFile dialog.
I selected the lengthy file path which is more than 512 bytes ( Jsapanese file path)
the return value from the doModal() is IDOK.
if I try to get the file name using the GetPathName(), it returns invalid truncated string.
Please let me know any way to get whether the file path returned is truncated or how to get the correct full path.
even the GetLastError() function return zero at tthis scenario.
Thanks in advance
sandeep
|
|
|
|
|
What is the size fo the buffer that you passed?
There is a member variable in the CFileDialog class called m_ofn which is an OPENFILENAME structure.
Get hold of the lpstrFile and pass a TCHAR buffer that is enough to hold the file name.
Nibu thomas
Software Developer
|
|
|
|
|
Yes I tried that by passing the maximum buffer, but still it return only truncated string. I looked into the implementation of the GetPathName() function and came to know that, it is returning only MAX_PATH. Current selected path is beyond the MAX_PATH.
|
|
|
|
|
An update to my analyses is, it can return the file path upto 260 characters ( not bytes). If the selected path is beyond the 260 characters, it truncates.
This scenario is possible when the folder path it self will be almost equal to 260 characters. Now if we select that folder from save as dialog to save some file, it truncates the path.
Please le mt know whether I can change this to return me the full path.
Thanks in advance
Sandeep
|
|
|
|
|
UNICODE chars are two bytes long.
So make sure you supply the required buffer for this purpose. If you are using MAX_PATH then use (MAX_PATH*2) .
Nibu thomas
Software Developer
|
|
|
|
|
Hello,
I'm trying to learn about overriding operators, so i wrote a simple class, Overrider, which allocates a small instance variable (an array) in its constructor. The problem is with the + operator; if I allocate the return object on the stack, it calls the destructor at the return statement, so for the statement
Overrider a, b, c;
...
a = b + c;
the object returned by (b + c) from operator + is not valid when it gets to to the operator = for a. When I trace the call stack, the destructor is called, and the instance-variable array is deleted, before it can be copied in the = operator.
If I allocate the object on the heap, the object returned from operator + is valid in the = operator, but then there's a memory leak.
I'm clearly missing something simple; I can post the code if that'd help, or if someone has a pointer to a tutorial that shows an example of overriding + when the class allocates memory in the constructor, I'd be appreciative.
thanks,
ed
|
|
|
|
|
|
Here's the code for operator +:
Overloader
Overloader::operator+ (
const Overloader& addend) const
{
Overloader result;
long v;
short* resultVoxels;
short* addendVoxels;
if (!result.Allocate()) {
return result;
}
for (v = 0; v < iNShorts; ++v) {
result.mArray[v] = mArray[v] + addend.mArray[v];
}
return result;
}
I think I've found the problem: I didn't have a copy constructor. I just implemented
one, performing a "deep" copy of the mArray instance variable, and now it seems
to work....
Thanks for any advice,
ed
|
|
|
|
|
Hi,
I have no idea about certificates but a problem:
I have three things:
- a file *.pem ---> !-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----<br />
- a signed base64 string<br />
- an unsigned base64 string<br />
<br />
the signed base64 string must be verify and compare with the unsigned string.<br />
<br />
but how???
|
|
|
|
|
GetPeerName will work only for TCP ? in Multicast, for example, I'm trying many to one. so One Client keep listening to many servers. now I want to send back an ACK to the servers. how do I do? a sendto() can help? how? (Its all UDP)
NULL
|
|
|
|
|
Meat Loaf wrote: GetPeerName will work only for TCP ?
Correct. UDP is a connectionless protocol so there is no notion of a peer. There is a sender and a receiver; once the data is transferred, there is no connection between the two.
recvfrom() will tell you the address of the sender, so you can use that address for sending back the ACK. Be aware that the ACK may not actually arrive - UDP does not guarantee delivery.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I have only a modicum of basic knowledge about programming in VC++6. Most of the time I am cold so I program to raise my body temperature by the unadulterated frustration C++ affords. However, this frustration is offset by the learning experience.
I’ve written a newsgroup client that downloads headers and articles from up to 10 newsgroups and deletes duplicates. My socket connection is derived from CAsyncSocket. It seems to run OK but since I have time, I was wondering if modifying the code by adding multi-threading would improve download performance. (I don’t even know if that is possible.) My newsgroup server allows 2 connections per host. I connect via a cable modem, only one PC is involved, and no router. My thought was that I might see only a marginal improvement since some delays, for example within the server, would still exist.
Regards
|
|
|
|
|
> if modifying the code by adding multi-threading would improve download performance
My short answer is: No. CAsyncSocket was designed to handle multiple sockets in one thread context (if you can have 2 connections to the server it's possible to create two socket instances in your application and split up download tasks among them). You could try a completely different socket architecture (with something else than CAsyncSocket), I don't see the need in your example.
/M
|
|
|
|