void DoSomeCalculation()
{
// here i may create a dynamic array using dynamic memory faciliites
// provided in c/c++ like
int arrSize = 0;
// get size from user or any other way
// create the array based on the new size
int* arr = new int[arrSize];
// here we may use the created array for some work
// before returnning from this functions
// we must delete and free up the created dynamic memory
delete[] arr;
}
// to use debug information, just added these lines to your program
// note: you should add them as is, do not change thier order
#define _CRTDBG_MAP_ALLOC
#include
#include
// after adding these,
// you can easily add this line as a first line in your program
// to enable debugging info in the output windows
// when this app close for any reason, normally or not
// this function will check this mem. app for leaks and such things
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF );
/*
something to know, we passed these flags to the previous function
to allow tracking of memory even when your program have the probaility
to exit at many diffrenet places
*/
// let say we have a pointer defined like this
IDirect3DDevice9* device = 0;
// and we need to pass this pointer address to some functions that
// will create this device for us (this just example to provide the idea)
/*
NOTE: even if these functions that we will call them and pass them
our variable (which is pointer) just need the device to be in this
form IDirect3DDevice9*, we also must use the method provided here
NOTE: C++ alwayes pass parameter by copying thier value.
*/
// we may define the function here like that
void function(IDirect3DDevice9** d)
{
// work with 'd' here and create it or even do whatever you wish
}
// or like that
void function2(IDirect3DDevice9* &d)
{
// work with 'd' here and create it or even do whatever you wish
}
/*
when we wanna pass the variable 'device'
we just call the function like that
function(&device);
or
function(device);
*/
في Jan 30, 2008 00:55، عقد ahmed ezz حاجبيه بتفكير وقال:
ثالثا : اذا كان لدينا متغير من نوع مؤشر مثل IDirect3DDevice9* ونريد ان نمرر هذا عنوانbool LoadLevel(const char* levelName, IDirect3DDevice9** outputSurface);
تصبح
bool LoadLevel(const char* levelName, PDIRECT3DSURFACE9* outputSurface);