|
You need to show the exact code. And please use <pre> tags around the code blocks so it is more readable thus:
mStrMap.Lookup(_T("4001"),tstStr);
mStrMap.Lookup(_T("4002"),tstStr);
mStrMap.Lookup(_T("4003"),tstStr);
mStrMap.Lookup(_T("4004"),tstStr);
You can automate that by selecting all the lines of code in the editor and using the code button at the top.
|
|
|
|
|
Sorry, it's my fault too. I read BOM, forgot to change the key string.
|
|
|
|
|
Please read the pseudo code as follows:
class A
{
CMap myMap;
A() {
myMap.InitHashTable(857);
}
};
void test(void)
{
A *pa = new A();
}
My question is, myMap member in A class is in Heap or Stack?
is destructor of A class need to delete myMap object expressly?
|
|
|
|
|
The actual memeory used by the Map is allocated internally and dynamically, so it will be on the Heap. You may need to delete the map in your destructor, it depends on the lifetime of your object.
|
|
|
|
|
So, the myMap memory allocation is dominated by it's container class A, right?
for pseudo code like the following:
void test() {
CMap myMap;
}
then I dont need to delete myMap expressly, right?myMap should be in function stack.
|
|
|
|
|
That is correct, as far as I recall; MFC classes clean up after themselves.
|
|
|
|
|
I try to use delete myMap, IDE shows cannot convert from 'CMap' to 'Void*'.
|
|
|
|
|
You need to show us your code, we cannot guess what you have done.
|
|
|
|
|
class A
{
private:
A m_Map;
public :
A();
~A();
};
A::A()
{
m_Map.InitHashTable(MAP_LEN);
}
A:~A()
{
delete m_ConfigMap;
}
error C2440: 'delete' : cannot convert from 'CMapStringToString' to 'void *'
|
|
|
|
|
I see two issues here:
1. Where is m_ConfigMap declared?
2. You have m_Map declared as an A . Is that what you meant?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
sorry, yes, m_configMap should be m_Map.
|
|
|
|
|
That code makes no sense. You declare m_Map as an object of class A . You then try to call InitHashTable on it in the constructor, even though that function is not declared anywhere. Finally you try to delete m_ConfigMap which also is not declared anywhere.
|
|
|
|
|
I am using DirectShow "common" dshowutil.cpp file and I just found this, to me new , usage of #include directive.
It only works if included in a source file where its function(s) are used.
Makes sense.
Elsewhere the linker generates multiple definitions, so it must be included somewhere else, I did not search for it.
Here is the #include:
#pragma message("Common DirectShow support ")
#include "D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\Common\dshowutil.cpp"
And here is the usage sample:
TRACE("\nFind input and output pins and connect them");
IPin * pCapOut = GetOutPin( pDocument->pC_Graph->gcap.pVCap, 0 );
In my view it prepends the working source file.
I would like some other explanations from the group.
Is such usage of including cpp file common?
Thanks for your time.
CHeers
Vaclav
|
|
|
|
|
The #include statement is a preprocessor directive. The preprocessor is reading input files, processes his commands, and writes the result to an output file (source file name with extension 'i'). The #include statement just inserts the processed content of another file.
When invoking the compiler, the preprocessor is started first for each source file and the created preprocessed file is the input for the compiler. After compilation the file is deleted (the deletion can be omitted by passing a compiler option flag on the command line or setting it in the VS project setting).
It is not very common to include other source files but allowed.
|
|
|
|
|
Vaclav_Sal wrote: In my view it prepends the working source file But that is perfectly acceptable as long as all required include files are added within that cpp file. It is just the same as adding some extra functions at the top of a source file before the #include statements required by the remainder of the source.
|
|
|
|
|
So are the include cpp functions global only to the attched cpp which is basically an object / class?
Is that the reason I was getting multiple definitions when I included it in StdAfx header?
I did not try to access the preprocessed functions outside the class. It should not work.
Actually found that I was telling the DirectShow to add another filter and had no intermediate filter / pins to connect to. Fixed that so I do not need to do the connections manually.
|
|
|
|
|
Without seeing all the code in the included file it is impossible to answer that.
|
|
|
|
|
You are spot on Val you will get multiple inclusions if the file is multiple included, unless the file contains standard one time load #ifdef protection around the top and bottom
If the programmer knew what they were doing they would have something that looks like this top/bottom of include file
// PROTECTION TO STOP MULTIPLE UNIT LOADING
#ifndef _FILENAME_ID_
#define _FILENAME_ID_
#endif
It is still quite common in a very specific circumstance .. can you think what it might be
I will give you a hint:
I know the old version of windows.h from Microsoft did it but they changed it all a few years ago when they broke that unit up. You will probably also find it on the android source unless they worked there way around it.
|
|
|
|
|
I use a CmapStringToString object, put over 10000 key-value pairs into the object.
But I use:
test1 = mStrMap.GetCount();
test2 = mStrMap.GetHashTableSize();
try to get the map size.
test1 = 0x00000299
test2 = 0x00000011
I wonder what the meaning of GetCount(), and GetHashTableSize();
modified 5-Mar-14 11:12am.
|
|
|
|
|
With the following code
CMapStringToString mss;
for (int i=0; i<10000; ++i)
{
CString k,v;
k.Format("%05d", i);
v.Format("Foo%02d", i%100);
mss[k] = v;
}
int count = mss.GetCount();
int hsize = mss.GetHashTableSize();
I get:
count = 10000
hsize = 17
I don't know what exactly GetHashTableSize returns, the documentation is not much detailed about.
Veni, vidi, vici.
|
|
|
|
|
My fault, checked again, GetCount() works well for me too.
|
|
|
|
|
|
Sorry, my fault, checked again, GetCount() return value is right.
but don't know what is the meaning of GetHashTableSize();
|
|
|
|
|
That's why I gave you a link to the MSDN page that explains it.
|
|
|
|
|
Determines the number of elements in the hash table for the map. // msdn: GetHashTableSize();
Retrieves the number of elements in the map. //msdn: GetCount()
And I read some articles, they say Hashmap is equivalent to Hashtable.
So, what is the difference between GetCount() and GetHashSize() confused me
|
|
|
|