Anonymous user
C++: Difference between revisions
Remove wrong advise that g++ doesn't support -ffreestanding and fix size_t declaration.
[unchecked revision] | [unchecked revision] |
m (There is no longer a special C++ Bare Bones, this has been merged into the standard Bare Bones article for maintainability. The constructor advise is not in that article, either.) |
(Remove wrong advise that g++ doesn't support -ffreestanding and fix size_t declaration.) |
||
Line 403:
== The Operators 'new' and 'delete' ==
Before you can properly use '''new''' and '''delete''', you have to implement some sort of memory management. You also have to implement both operators (including their array counterparts). '''new''' and '''delete''' respectively allocate and delete memory (much like '''malloc''' and '''free''' in C). Take a look at the [[Memory Management]] article if you would like to know more about this subject.
Every time you call one of the operators '''new''', '''new[]''', '''delete''', or '''delete[]''', the compiler inserts a call to them. The most simple implementation would be to map them to your kernel's '''malloc''' and '''free'''. For example:
<source lang="cpp">
#include <stddef.h>
void *operator new(size_t size)
|