Page 1 of 1

how to dynamically allocate space for objects of class

Posted: Fri Nov 28, 2008 9:22 pm
by osmosys
i have come to the situation where i have a function kdmalloc which allocates bytes like a usual malloc function and a class disk to read from a disk...the disk read function is working well when i create static objects...now i want to create objects dynamically with malloc

Code: Select all

disk *disk1 = (disk*) kdmalloc (sizeof(disk));
i know that this just reserves some space for disk1 object but doesn't make the function calls to it properly. when i call anyfunction on disk1 that was dynamically created it results in page fault, which means that functions of that object are not setup properly...what should i do to make them work properly ?? should i use new operator, i saw one such implementation of new operator with malloc on osdev wiki, but that too just reserves some space ?? what should i do .??

Re: how to dynamically allocate space for objects of class

Posted: Sat Nov 29, 2008 9:04 am
by JamesM
Use operator new. Implement it to use malloc - it *doesn't* just assign space, it assigns vtable pointers too.