how to dynamically allocate space for objects of class

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.
Post Reply
osmosys
Posts: 14
Joined: Sun Oct 05, 2008 4:33 am

how to dynamically allocate space for objects of class

Post 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 .??
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: how to dynamically allocate space for objects of class

Post by JamesM »

Use operator new. Implement it to use malloc - it *doesn't* just assign space, it assigns vtable pointers too.
Post Reply