|
If unsure, always put stuff like that after your system includes, but before your own.
--
Behold, for I am THE CORRUPTOR!
|
|
|
|
|
Robert - what I often find to work quite nicely (without redefining 'new', which for some reason, I find slightly distaasteful - don't ask me why, probably a symptom of incipient OCD) is to use the allocation ID - add _crtBreakAlloc to a watch window, then set it to the ID of a leaking allocation. You'll then break within the debug malloc (actually in _heap_alloc_dbg ) when that allocation is made, so have access to the full call stack etc.
<code>
Detected memory leaks!
Dumping objects ->
{53} normal block at 0x002F3CF8, 4 bytes long.
Data: < > CD CD CD CD
Object dump complete.</code>
In this object dump, I have one leaked allocation, with ID 53. So, step into main for your app, then set _crtBreakAlloc to (decimal) 53 and run until you get a User Breakpoint exception dialog appearing. Press 'Break' and there you are! Last modified: 08 August 2006 02:21:44 --
|
|
|
|
|
Excellent - I assume this means the allocation IDs are reused between executions? If so, this is a great tip Stuart. Thanks.
|
|
|
|
|
Yes, and they stay the same, so long as the allocation pattern doesn't change (which is likely to be the case if you don't alter your code too much).
|
|
|
|
|
Hi All,
Anyone of you know how to use the FileMaker Pro Software to develop an ERP system?
Thanks.
|
|
|
|
|
What does ATL/WTL/STL have to do with it?
S o h a i l K a d i w a l a
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi
I am new to stl.
I see that we don't need to delete our containers
For example:
vector <char> vec;
But why?
Here, Does vec allocate in heap or stack by default.I heard that Although we don't create vec without new , it is allocated in heap and automatically delete it.Is this true?
If true i tried this:
vector <char>* vec = new vector<char>;
delete vec;
it doesn't give me error.Here this mustn't work.Am i wrong?
I looked to google, there are so many things about stl but i can't find explanation about relationship between stl containers and heap,stack allocation(or new ,delete).In what circumstances are stl containers allocated in heap or stack.And In what circumstances do we need to delete our containers?
Can you please explain me.
Thanks...
|
|
|
|
|
It's basic C++.
class X {
int* p;
public:
X() : p(new int[100]) { }
~X() { delete [] p; }
};
void function() {
X x;
} x is an object allocated in the stackframe of function . X::p however is allocated on the heap, as it's done so by new . std::vector is no different.
--
Simulcast on Crazy People's Fillings
|
|
|
|
|
|
Have a look at the tutorials on this site.
Typically you just declare the STL containers on the stack.
vector<int> vec;
vector<MyClass> vec;
You can add simple types and objects to the vector and you don't need to worry about memory management <i>unless </i>those individual simple types or objects were themselves dynamically allocated.
Kevin
|
|
|
|
|
template <typename T>
struct Deleter { void operator(T* pObj) { delete pObj; } };
template <typename Collection>
void DeleteAllObjects(Collection& coll)
{
std::for_each(coll.begin(), coll.end(), Deleter<Collection::value_type>());
coll.clear();
};
--
Based on a True Story
|
|
|
|
|
Yes, I have a similar utility functor myself, but I haven't done any C++ for 18 months. I'm in the .NET universe now. I guess I may do some C++/CLI some time.
Kevin
|
|
|
|
|
Problem with firing events
I created an ATL/COm dll. and I'm testing it with a VB client. The client behaves fine in the IDE (VB6.0)
But once we create the .exe and run it, It crashes the application when an Event is fired from the DLL
I narrowed down to the point where it actually crashes. It's failing when we say,
this->Fire_testEvent()
inside the implementation,
it fails here.
<br />
HRESULT Fire_testEvent()<br />
{<br />
CComVariant varResult;<br />
T* pT = static_cast<T*>(this);<br />
int nConnectionIndex;<br />
int nConnections = m_vec.GetSize();<br />
<br />
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)<br />
{<br />
pT->Lock();<br />
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);<br />
pT->Unlock();<br />
IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);<br />
if (pDispatch != NULL)<br />
{<br />
VariantClear(&varResult);<br />
DISPPARAMS disp = { NULL, NULL, 0, 0 };<br />
</pre>pDispatch->Invoke(0x6, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
</pre> }<br />
}<br />
return varResult.scode;<br />
<br />
}<br />
Please help me .. what could be wrong.. It's killing me.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
Are you by any chance firing the event from a secondary thread?
If you want to fire events from other threads than the one that created the server, you have to marshal the sink interface pointer.
Have a look at Michael Lindig's solution here[^], I've used it quite a lot.
If you're not using multithreading, post again and describe your app further.
--
Rog
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Yup exactly, I fire it from a worker thread. So that's the culprit? hmm.. thanks for your valuable help. Thanks you so much. I'll go through the link. and comeback here again. But Roger I have a question. How does it work, when I test the application in the IDE ? and what makes it fail after I create the .Exe file?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
I'm glad I could help you, even if I guessed about your problem.
Regarding VB and why it works running from the IDE:
I don't know the technical reason for it, but VB is quite forgiving when running from the IDE. I guess (again... ) that VB makes some kind of qualified guess and if you're "lucky" it works.
Aahh, I forgot a few really important things: you have to set up the apartment as well from your secondary thread with a call to ::CoInitialize(). If you haven't done so yet, this could be the reason that it works when running from the IDE. If it's an in-process server it would be the same thing as using a function pointer even if the call is made from another thread. If you properly set up the secondary apartment you could get a HRESULT = RPC_E_WRONG_THREAD, especially in you're running the server out-of-process.
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Had to solve other problems in my project. I should spend a while to fully understand it and implement. anyway I'm leaving office with a complete peace of mind only because of Mr. Roger Stoltz. . thanks!! .. see you on monday. Happy weekend
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
Have a nice weekend yourself.
You saved my weekend with your kind replies!
Careful with the beer, mate! Your belly measures are at risk!
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Hello buddy Just fixed my thread-event problem. It's working fine now . Thank you so much Roger. I was really shocked to find the pDispatch->Invoke(0x1, line of code crashing the application. I was clueless what on earth makes it fail with the .exe. Hmmm.. now everything's fine chilling out a bit.. .. thanks again
[Roger].
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
Nice!!
Thanks for all the 5-votes, but go easy on them otherwise they won't be worth much. Inflation you know...
--
Rog
-- modified at 9:45 Tuesday 8th August, 2006
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
oh! yeah . but you know I got a little excited about fixing the issue. So all excitement turned into 5s
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
Roger, got a problem. The DLL works fine with windows application. But I'm trying to use it with an ASP page. In that page, I'm able to access all the properties & methods but not the events. Events are not getting fired. Things are different with the Browser? You have any clue?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
I have inherited a COM class out of CComObjectRoot and CComObject using the ATL thingy. Everything compiles fine, but when i try to create an instance of the class, VC2003 breaks due to NULL pointer. It seems that for some reason CComObject depends on the _pAtlModule global variable which for some reason is NULL.
Should the ATL library be initialized in some way before use?
Here is the code where the app crashes from <atlcom.h>
---
template <class Base>
class CComObject : public Base
{
public:
typedef Base _BaseClass;
CComObject(void* = NULL) throw()
{
_pAtlModule->Lock();
}
|
|
|
|
|
I am just now learning COM with ATL, but will try to help.
_pAtlModule is a global variable declared in atlbase.h as:
__declspec(selectany) CAtlModule* _pAtlModule = NULL;
It is set in the constructor of "class ATL_NO_VTABLE CAtlModule : public _ATL_MODULE":
_pAtlModule = this;
So, if you have the normal ATL generated code in your main project file
class CMyATL_ProjectModule : public CAtlDllModuleT< CMyATL_ProjectModule ><br />
{<br />
public :<br />
DECLARE_LIBID(LIBID_MyATL_ProjectLib)<br />
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYATL_PROJECT, "{157A51E9-ECF7-4D1B-8D66-694A7CEFB436}")<br />
};<br />
<br />
CMyATL_ProjectModule _AtlModule;
that global field will be set when you compile your program.
|
|
|
|
|
> So, if you have the normal ATL generated code in your main project file
Well, no i dont. You see i dont have any need for an entire ATL project. What i need to do is to implement a single COM interface. So i hoped that i could just extend the CComObject class and have it done the easy way, instead of writing all the COM stuff myself.
This is what i came up with:
---------------------------------------------
class CSampleProsessorRoot : public CComObjectRoot, public ISampleGrabberCB
{
public:
HRESULT STDMETHODCALLTYPE SampleCB(double SampleTime, IMediaSample *pSample);
HRESULT STDMETHODCALLTYPE BufferCB(double SampleTime, BYTE *pBuffer, long BufferLen);
DECLARE_NOT_AGGREGATABLE(CSampleProsessorRoot)
BEGIN_COM_MAP(CSampleProsessorRoot)
COM_INTERFACE_ENTRY(ISampleGrabberCB)
END_COM_MAP()
};
typedef CComObject<CSampleProsessorRoot> CSampleProsessor;
|
|
|
|