Page 1 of 1

Problem with global objects

Posted: Thu Jan 18, 2007 5:23 am
by RedEagle
Hi
I wrote a class to output debuginformation on the screen.
Now i want to debug my Memorymanager, so i have to use one object from this class for more than one function. It has to be global.

To execute the Consturcftor and deconstruktor of a global object I had to write some special functions which i executor befor starting and at the end of the kernel.bin
This functions work! The constructor is execute on start with no errors.

And now the Problem:
I initialize the object by calling the method "init(...)". Ther I can define the Position of the Output (cursorposition), the color and some
other things.
After that I can print some text on the screen.
I do that all at the "InitMemoryManager"-function.

Now I want to print some information when I call the "GetMemoryBlock"-function (this happens when I want to get some memoryspace)
but ther is no output :(. If I call the print-method of my global objekt it won't be execute.

But if i call the init-method befor, it works. So I think/know, after leaving a function, all information which were stored in the *variablen*
get lost.

So, now some code:
a very short version of the Class:

Code: Select all

class klasse
{
public:
  klasse(){init(0x07,0,0);}
  ~klasse(){;}

  void init(BYTE farbe, BYTE xposition, BYTE yposition);

private:
  BYTE *frontbuffer;
  BYTE color;
  BYTE x;
  BYTE y;
};

void klasse::init(BYTE farbe, BYTE xposition, BYTE yposition)
{
 x = xposition;
 y = yposition
 color = farbe;
 frontbuffer = (BYTE*)0xB8000;
}
and the memorymanager

Code: Select all

 flowbox wnd;

 bool SetupMM()
 {
   wnd.init("MemoryManager2", 49, 39, 31, 11);
   wnd.DrawFrame();
   wnd.DrawBody();
   wnd.DrawFlow();
   wnd.DrawTitle();
   wnd.setcolor(FLOWBOX_STDFLOWCOLOR);
   wnd.printsc("SetupMM()\n", 0x1E);   
   
   //...
 }
 
 bool GetMemoryBlock(memblock **block, DWORD size)
 {
   //wnd.init("MemoryManager2", 49, 39, 31, 11); //if I call this method, it will work
   wnd.printsc("GetMemoryBlock(...)\n", 0x1E); //does not work. The text will be writte @ the address 0x0
   
   conio::setcolor(0x0C);
   conio::print((CHAR*)"# "); //works
  
  //...
  
 }

I hope that someone can help me.

Posted: Thu Jan 18, 2007 7:41 am
by Otter
Are you sure all initialize code is executed in the beginning ? Maybe you should simply use a global pointer to your flowbox, this is much easier and should work.

If you don't want to use a pointer:
To execute the Consturcftor and deconstruktor of a global object I had to write some special functions which i executor befor starting and at the end of the kernel.bin
This functions work! The constructor is execute on start with no errors.
Could you tell more about about this and maybe about the linker script you use ?