Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Feb 2009
Offline Last Active Nov 30 2014 02:25 PM

Topics I've Started

[C++] Custom containers vs STL

01 March 2012 - 12:15 AM

Hi all,

I want to write my own container classes and I've some questions.

I've learnt that when we want to add one or more elements to an STL container (e.g. std::vector), it increases the size of the buffer more than we want. For example, if we have a 4-element-vector and if it's capacity is 4, when we want to insert 3 elements somewhere in it, it sets the capacity (or size, whatever you say) more than 7 (e.g. 10). I think this is done to avoid calling ::operator new frequently. But the size increases unnecessarily, right?

So, for an STL-like custom container, which one is more expensive?:
a) Using new/delete every time we want to add/delete elements (To keep the size of the buffer exact: for an n-element-buffer, the size is n*sizeof(element_type) ).
b) Increasing the capacity unnecessarily (To avoid calling ::operator new and ::operator delete every time).

btw, I've heard about "heap compaction" but I don't have any idea about that.

Hope I could describe.

Thx in advance.

A complex inheritance problem

22 October 2011 - 09:25 AM

Hi all,

I can describe my problem only throug a sample code. Sorry for that.

I've a class inherited through IUnknown (and I want to hide some members):

#define _INTERFACE(IName) interface DECLSPEC_NOVTABLE IName : public IUnknown
#define _INTERFACE_(IName, IBase) interface DECLSPEC_NOVTABLE IName : public IBase

      //AddRef(), Release(), QueryInterface() come here!

  	void A1_Func(float y);
////////// end of a1.h /////////////

struct A1_D : public A1
  	/*  AddRef(), Release() and QueryInterface() definitons come here!  */
 	float x;
 	ULONG _ref_count

inline			A1_D* CImpl (A1* ptr)		{ return (		A1*)ptr; }
inline	const	A1_D* CImpl (const A1* ptr)	{ return (const A1*)ptr; }

void A1_Func(float y)
 	A1_D* pA1_D = CImpl(this);
 	pA1_D->x = y;
////////// end of a1.cpp /////////////

Now I want a class inherited through A1:

 	void A2_Func();
////////// end of a2.h /////////////

struct A2_D : public A2
 	/* AddRef() etc. definitons come here! */


It seems that A2::A1_Func() does not work properly.

How can I do this?

Hope I could explain.

Thanks in advance.

Memory Leak Problem

08 May 2011 - 07:23 AM

Hi all,

I'm working on D3D9 device enumeration. Everyting works fine (I can say "fine" because my enumerator outputs same results with DX Caps Viewer). But I've a problem with memory leak. Even if I destroyed everything in my app. I'm sure I'm calling all the destructors, ReleaseCOMs etc.

Here's a list of what I do:
1) Opening Windows Task Manager and jumping "Performance" tab. Looking at SD Usage. It's now 789 MB.
2) Creating a windowed D3D9 application. Doing something. Rendering blah blah. Still looking at SD Usage. It's now 811 MB.
3) Exiting that application. Looking at SD Usage. It's now 789 MB. It means, my application gives back the memory it used. Right?

The Problem:
But, if I create a fullscreen application instead of a windowed one, especially with different sizes from my desktop (e.g. my desktop is 1920 x 1080 and I'm creating a 1280 x 768 fullscreen app), SD Usage is over 789MB after I closed my app!

Why/how does it occur? Is that normal? If not, how can I deal with this?

Thanks in advance.

Using release DLLs in Debug mode.

20 March 2011 - 04:08 PM

Hi all,

I'm writing some DLLs for my renderer. I'm compiling'em both in Release and Debug.

When I create a new project in VC++2008 and in Debug mode, I think I must be able to use either Debug or Release runtimes in Debug mode of the project.

My window creation function like this:
 	std::string name;
 	UINT width, height;
 	DWORD style;

declspec(__dllexport) HRESULT

//some other functions...

I'm filling ZE_WINDOWCREATION_PARAMETERS struct in the application then passing to the ZECreateWindow() function. When the application runs in Release mode and I link Release Runtime DLLs, no problem, works as expected.

But when the app in Debug mode and Release Runtime DLLs are linked, I saw that some values in ZE_WINDOWCREATION_PARAMETERS struct changes automaticially.
For example;
//in application
ZeroMemory (&wcp, sizeof (ZE_WINDOWCREATION_PARAMETERS));

wcp.name = "(Unnamed)";
wcp.width = 1024; wcp.height = 768;
HRESULT hrW = pWindow->ZECreateWindow (&wcp);


//in DLL's source

 	this->m_uWidth =  pWCP->width;	//->becomes 0,
 	this->m_uHeight = pWCP->height;	//->becomes 1024

	//blah blah

As I told in commented lines, member values in pWCP are changing: width becomes 0, height becomes 1024, style becomes 768 etc. But I passed 1024, 768 and WS_OVERLAPPEDWINDOW, respectively.

Professionally coded DLLs work in either Release or Debug mode. But mine doesn't :(

Why this occurs? What can you suggest to solve this?

Thanks in advance.

[DX9] Cannot draw on Debug mode.

20 March 2011 - 10:50 AM

Hi all,

I'm creating a box mesh (created via D3DXCreateBox() func.) for rendering tests.

My problem is: My D3D App. doesn't draw that mesh on Debug mode, but does on Release mode!

I'm using VC++ 2008 and in Linker options, I put d3dx9d.lib for Debug, d3dx9.lib for Release mode. When I put d3dx9.lib for Debug, nothing changes!

What can cause that?

Thanks in advance.