I
Immortal Nephi
I use class to create some objects. Objects such as line, circle,
and other shapes are drawn on the screen.
main function has its own responsibility to allocate Pixel Buffer
into memory and release it from memory when Test class is finished.
However, Test class needs to access Pixel Buffer directly. If either
Draw_Line function or Draw_Circle function attempt to access unknown
memory, then the eror message is triggered by operating system to tell
execution violation or security denied.
I decided to place default constructor to private. The constructor
with parameter is required.
What happened if pointer to address memory variable in Draw_Line
function does not have memory allocation? You will get the same
message from operating system. You need to use safe checking
mechanism.
Each function requires to test if memory is already allocated or
not. It will return to false, otherwise allows to execute and return
true.
I will create multiple objects from one Test class and multiple
objects are drawn on the screen. Please let me know if safe checking
mechanism is best practice.
Typedef unsigned short TUWord;
class Test
{
public:
Test ( TUWord* pui_PixelBuffer ) : pmui_PixelBuffer
( pui_PixelBuffer ) {}
~Test() {}
bool Draw_Line( TUWord X, TUWord Y, TUWord width )
{
if( pmui_PixelBuffer == 0 )
return false;
// Do something to draw
// Fill RGB data into Pixel Buffer
return true;
}
bool Draw_Circle( TUWord X, TUWord Y )
{
if( pmui_PixelBuffer == 0 )
return false;
// Do something to draw
// Fill RGB data into Pixel Buffer
return true;
}
private:
Test() {}
Test( const Test & ) {}
Test &operator=( const Test & ) {}
TUWord* pmui_PixelBuffer;
}; // end class Test
int main()
{
TUWord* Pixels = new TUWord [ 1024 * 1024 ];
// Test private_t; // Error private constructor
Test t( Pixels ); // Grant constructor with parameter
t.Draw_Line( 10, 10, 150 );
t.Draw_Circle( 50, 50 );
delete [] Pixels;
return 0;
} // end function main
and other shapes are drawn on the screen.
main function has its own responsibility to allocate Pixel Buffer
into memory and release it from memory when Test class is finished.
However, Test class needs to access Pixel Buffer directly. If either
Draw_Line function or Draw_Circle function attempt to access unknown
memory, then the eror message is triggered by operating system to tell
execution violation or security denied.
I decided to place default constructor to private. The constructor
with parameter is required.
What happened if pointer to address memory variable in Draw_Line
function does not have memory allocation? You will get the same
message from operating system. You need to use safe checking
mechanism.
Each function requires to test if memory is already allocated or
not. It will return to false, otherwise allows to execute and return
true.
I will create multiple objects from one Test class and multiple
objects are drawn on the screen. Please let me know if safe checking
mechanism is best practice.
Typedef unsigned short TUWord;
class Test
{
public:
Test ( TUWord* pui_PixelBuffer ) : pmui_PixelBuffer
( pui_PixelBuffer ) {}
~Test() {}
bool Draw_Line( TUWord X, TUWord Y, TUWord width )
{
if( pmui_PixelBuffer == 0 )
return false;
// Do something to draw
// Fill RGB data into Pixel Buffer
return true;
}
bool Draw_Circle( TUWord X, TUWord Y )
{
if( pmui_PixelBuffer == 0 )
return false;
// Do something to draw
// Fill RGB data into Pixel Buffer
return true;
}
private:
Test() {}
Test( const Test & ) {}
Test &operator=( const Test & ) {}
TUWord* pmui_PixelBuffer;
}; // end class Test
int main()
{
TUWord* Pixels = new TUWord [ 1024 * 1024 ];
// Test private_t; // Error private constructor
Test t( Pixels ); // Grant constructor with parameter
t.Draw_Line( 10, 10, 150 );
t.Draw_Circle( 50, 50 );
delete [] Pixels;
return 0;
} // end function main