I was wonder how malloc would allocate memory (can you tell me ?), so I tried something.
Is this a bad way to allocate memory ?
void* myMalloc(unsigned int size) {
return (void*) new bool[size];
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I hate to disagree with quite so many people recommending that you use
new char[n], but I feel obliged to do so.Since you want to allocate “raw” memory, not objects, you should really use
::operator newinstead ofnew some_type[some_size]:Ultimately,
new char[whatever]isn’t particularly harmful, but (at least IMO) it’s conceptually wrong, and I see no advantage over using::operator newdirectly.