OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 10:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Operators new and delete
PostPosted: Tue Jun 09, 2020 10:50 am 
Offline
Member
Member

Joined: Sun Apr 05, 2020 1:01 pm
Posts: 183
Hi guys, just implemented my first kernel heap allocator and I'm kinda confused about the C++ operators...

Why does this call the delete with size_t?
Image

I did read this page https://en.cppreference.com/w/cpp/memor ... tor_delete but it says that they're called
only if user defined implementation is provided, but if I don't provide them GCC starts complaining and it results in an undefined reference...
(I'm using C++17)

Thanks :)


Top
 Profile  
 
 Post subject: Re: Operators new and delete
PostPosted: Tue Jun 09, 2020 11:46 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
I am not a C++ expert, I mainly know C, but in the picture, it says there are 4 overloads. That tells me that is one way to define it. You could also try using a lower standard and see if that helps.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Operators new and delete
PostPosted: Tue Jun 09, 2020 6:06 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
It is rather trivial to implement new/delete. Here is what I use (I didn't implement all overloads as I didn't need them):

Code:
inline void* operator new(size_t, void* p)      { return p; }
inline void* operator new[](size_t, void* p)    { return p; }
inline void* operator new(size_t size)          { return ::malloc(size); }

inline void operator delete(void* p)            { ::free(p); }
inline void operator delete(void* p, size_t)    { ::free(p); }

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 108 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group