Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
fifo_t keys;
int init_kbd()
{
keys = new fifo_t (0x100); //0x100 last keypresses
}
as I want to use the list later, it has been already disposed... I also found this on strings: each time i create a s = new string; it gets disposed after function end. This is nasty when I want to have a string list during all the execution... is this something well known or a misbehavour of g++?
First point : new is returnin a pointer, so make your lvalue check this.
Second point : is this for OSdeving ? because you can only use a redefinition of the new operator (no RTTI for a C++ kernel).
actually, it was a typo. I did define it as *keys. And I have a working kmalloc() + kfree() implemenetation. I overloaded the new, delete operators. Now if I call new in a function, the object will *always* be disposed after the end of the routine. This is not comfortable for setting global tables, etc. I think there should be an option to turn it off; I'll check and tell you if I find one.
No, this is not an option. It is broken. Returning from a function does not dispose of data allocated using new. It does destruct objects declared local to the function, but it doesn't touch objects allocated using new. Either there is a really big bug in gcc, and nobody's noticed, or there's a mistake in your code.
I have checked many times in various subfunctions that if now I save the pointer to the buffer somewhere and I want to read again, it may
1) report the string I put into it, that's when I do a string::asciiz = NULL before ending the first function
2) have garbage; as I checked further, the buffer was reckoned free space on the heap.
I suppose it's just g++ wanting my memory to be managed well and if I forget to dispose an object it does itself. This was a nasty bug when I allocated syms lists, each sym name was garbage
If you were writing Java or C# code I could understand the compiler wanting to clean up your allocations for you, but not C++. You have to try hard to get C++ to do garbage collection, so it's not going to do it behind your back.
It looks to me like some other part of your code is overwriting stuff it shouldn't be. I think you need to work out what is happening, or it will come back and bite you later. Start by reducing your code down until it behaves correctly, then start adding bits back until it stops working. Then you will know that the error lies in what you just added.
Bugs like this are a real pain, but better to get them fixed now while your kernel is still small, than later when there are far more possibilities to eliminate while debugging.