Page 1 of 1

Keyboard Buffer

Posted: Fri Mar 07, 2003 8:20 pm
by AvengerX
Alright, i am using a struct for my consoles, but that's not the problem. the struct has members caled queue (a char *) and queuelen (an unsigned). there are 8 consoles (0-7). i type text in one console, switch to another and use my queue display key (ctl+sysrq+q) and it is the same as console 0 (and every other console.) i think that it is the fact that queue is a char *, but here is my code for setting the queue:

Code: Select all

                if(i != 0)
                {
                        console_t *curr_vc;
                        curr_vc = _vc + _curr_vc_num;
                        putch(i);

                        curr_vc->queue[curr_vc->queuelen] = i;
                        curr_vc->queuelen++;
                        curr_vc->queue[curr_vc->queuelen] = '\0';


                }
thank you in advance for any help you may provide. it is much appreciated.

Re:Keyboard Buffer

Posted: Sat Mar 08, 2003 12:36 pm
by Slasher
Are you allocating a seperate memory area for each console's queue (char *)?

Re:Keyboard Buffer

Posted: Sat Mar 08, 2003 12:58 pm
by AvengerX
I'd do this how? the allocation of memory for it? i have found a working way but it only provides a limited queue, and it's kind of hard to work with, so i'd like this way (the working way is a char[100]) and as i said i prefer a char *

Re:Keyboard Buffer

Posted: Sat Mar 08, 2003 1:22 pm
by Slasher
when you define, char *.... the pointer points to random address, you are lucky it works, could have overwritten your code, hard bug to find.

do you have a memory manager for memory allocation and deallocation?
if not then you could try this, dedicate parts in memory for each queue manually. but you need to make sure nothing else will overwrite those areas
console 1 queue: 0x9000 to xxxxx
console 2 queue: (0x9000+xxxx) to aaaa
...
...

Re:Keyboard Buffer

Posted: Sat Mar 08, 2003 4:07 pm
by Therx
No I think you'll be lucky on that until you've written a memory allocation(MM). The problem is that console_t is a structure of more than 1 byte so the pointer to it has to equal _vc plus the curr_vc_num times the size of console_t so

Code: Select all

console_t *curr_vc;
curr_vc = _vc + _curr_vc_num;
should become

Code: Select all

console_t *curr_vc;
curr_vc = _vc + _curr_vc_num * sizeof(console_t);

Re:Keyboard Buffer

Posted: Sat Mar 08, 2003 4:50 pm
by Tim
No, AvengerX was right in the first place. This is fundamental C array and pointer addressing.

These two lines are equivalent:

Code: Select all

curr_vc = _vc + _curr_vc_num;
curr_vc = (console_t*) ((char*) _vc + sizeof(console_t) * _curr_vc_num));