|
I recently added STL vector to some 3D classes I have in order to store a huge amount of datas. I've read somewhere that vector doesn't free object untill it is freed. But I thought that myvector.clear() would free the content.
I just experienced it doesn't:
My classes are prototyped like this:
<br />
class C3dObject<br />
{<br />
public:<br />
C3dObject(TCHAR* pszObjectName);<br />
~C3dObject();<br />
<br />
std::vector<C3dVertex*> m_vctVertex;<br />
}<br />
In the destructor, I just call:
<br />
m_vctVertex.clear();<br />
and this frees nothing (The C3dVertex class has the same prototyping).
Has someone an explanation to this ?
Thanks
Yarp
http://www.senosoft.com/
|
|
|
|
|
oops, my vector class is declared as follows (think it's due to tag like syntax in the vector's declaration):
<br />
std::vector<C3dVertex*> m_vctVertex;<br />
Yarp
http://www.senosoft.com/
|
|
|
|
|
vector doesn't free anything because the things it's storing aren't objects.
You're storing pointers. You'd need to modify it to be:
for( it = m_vctVertex.begin(); it != m_vctVertex.end(); ++it)
{
if (*it) delete (*it);
}
m_vctVertex.clear();
where it is an iterator, as usual. If the thing was an object itself, eg CString or struct xxx or whatever, then it would do what you expect.
Steve S
|
|
|
|
|
|
Thank you both for your explanation.
I thought this had something to do with pointer based vector, I understand why now... and btw Nemanja your article is very interesting.
STL obviously is a very powerfull concept.
Yarp
http://www.senosoft.com/
|
|
|
|
|
Background:
I am working on a system composed primarily of VB 6.0 COM components. I need to add a sub-system of ATL components in order to reuse some C++ code.
Problem:
Reusing the C++ code using ATL and having it interop with VB components requires the use of Automation (oleaut32.dll) compliant types (SAFEARRAYs) and VB compliant types (no unsigned types).
What I would like to do:
Some ATL components will have both VB clients and ATL clients. I would like to define non-VB friendly interfaces to be used by the ATL clients only. Another idea is to create interfaces that are not Automation compatible but mark them as [local] so that no proxy stub is required. I could use these interfaces to pass "non SAFEARRAY" arrays and such.
Do I know enough to shoot myself in the foot? I am afraid that I am making a ATL newby blunder.
Should I just make all the interfaces [oleautomation] and VB compliant? I hate to wrestle with SAFEARRAYs of four Bytes because I can't work with unsigned longs. This is non-risky but inelegant.
|
|
|
|
|
Hi all,
Where can i find atl service s tutorial for the very beginner?
10'x
|
|
|
|
|
I want to use XP-Style in ATL program;
I could make "XP-Style exe program" using manifest file and resource setting;
But in ATL project,I can't that.
I tried all method written MSDN,but I failed.
URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwxp/html/xptheming.asp
Is this problem solvable?Please teach me.
|
|
|
|
|
Are you running the ATL program on an XP or Win2k3 box? You won't get the XP style on anything less than XP.
|
|
|
|
|
I do not get "New ATL Object" in the "Insert" menu in the VC++ 6.0 with windows XP home edition. Could anybody help in enabling the above option.
Thanks
Prakash
|
|
|
|
|
Sounds like your project doesn't have ATL support.
Steve S
|
|
|
|
|
OOPS. That wasn't finished...
As I was saying, it sounds like your project doesn't have ATL support.
If you create a new project using "ATL/COM AppWizard", does that project have "insert ATL Object" as an option?
I'm sure that it used to be the case that it would ask if you wanted to add ATL support if it didn't have it.
An alternative is that you have some of the project files (like the IDL, the main CPP file) read-only (source control?) and this is why you can't do it.
Steve S
|
|
|
|
|
Thank you for your support.
No I am not getting "Insert ATL Object" when I build a project using ATL/COM wizard. I know there is a option when it shows all the controls in the New ATL object but some how I am not getting it.
|
|
|
|
|
Which edition of VC++ 6.0 are you using?
Steve S
|
|
|
|
|
I am using VC++ 6.0 Enterprise Edition.
Prakash
|
|
|
|
|
I have built the project with ATL-COM object wizard.
|
|
|
|
|
I want to set items' color individually in listview. Then I declare my listview as CContainedWindowT<clistviewctrl>, and receive NM_CUSTOMDRAW. On CDDS_PREPAINT draw stage, I return CDRF_NOTIFYITEMDRAW. On CDDS_ITEMPREPAINT draw stage, I return CDRF_NOTIFYSUBITEMDRAW. But I cannot receive CDDS_ITEMPREPAINT|CDDS_SUBITEM draw stage! Some one help me.
|
|
|
|
|
|
See Exporting from a DLL Using __declspec(dllexport) for your DLL and Importing into an Application Using __declspec(dllimport) for your client applications.
You will have to use the same header defining the class so that both sides can utilize the class. Note, you don't have to share the class implementation, just the structure, i.e., your class implementation is in a .cpp source file not as inline bodies in the .h header file.
The alternative is to use COM or .NET, which you said you couldn't do, but both preclude having to distribute a header file with your dll for consumption.
|
|
|
|
|
hi
i have an STL string object, which has a NULL char in the MIDDLE. For ex:
#include<string>
using namespace std;
....
string str = "abcdefghijklmnopqrstuvwxyz";
str[11] = 0; // str.size() still equals 26
Now i want to convert this string to _bstr_t object, retaining the NULL char and the chars after that. I tried this:
_bstr_t bstr = str.c_str();
But only first 11 chars are being copied(till NULL char). Pls help
TIA
|
|
|
|
|
Just replace all '\0' characters in your std::string with some token character which you can convert back once it's a BSTR. Remember BSTRings are 2 bytes wide in Unicode, so NULL is 0x0000.
|
|
|
|
|
basic_string , by definition, does not allow embedded 0 characters. When you stick a 0 in yourself, you're breaking the semantics of basic_string , so anything after that is not guaranteed to work.
You'll need to copy the string manually.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
If my rhyme was a drug, I'd sell it by the gram.
|
|
|
|
|
Michael Dunn wrote:
basic_string, by definition, does not allow embedded 0 characters.
Where did you find this information? AFAIK, the C++ standard does not mention this, and the only function that would be affected by embedded 0 characters is c_str()
|
|
|
|
|
hmm... That was just one of those things I saw in passing and it happened to stick in my memory. Of course, I can't find it now. So I could be wrong, don't quote me (well, you already did... don't quote me elsewhere )
The closest I can find is this:basic_string::c_str
const E *c_str() const;
The member function returns a pointer to a nonmodifiable C string constructed by adding a terminating null element (E(0)) to the controlled sequence. Calling any non-const member function for *this can invalidate the pointer. That's one aspect that treats E(0) as special, E(0) being '\0' for character strings. Since the caller of c_str() can look for E(0) to mark the end of the returned string, an E(0) in the middle of the string also looks like the end.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
Yep, embedded zeros can screw c_str . However, I made this little experiment:
char buffer[] = {'h','e','l','l','o', 0, 'w', 'o', 'r', 'l', 'd'};
string s (buffer, sizeof(buffer));
cout << s << " length = " << s.length()<< endl;
And the output (VC 7.1) is:
hello world length = 11
|
|
|
|