473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

malloc and new

Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen

Nov 9 '06 #1
4 1179
"Mohsen" <ja*******@gmail.comwrote in message
news:11*********************@h54g2000cwb.googlegro ups.com...
: Dear All,
: Do you know if there is any difference between 'new' and
: 'malloc' in terms of handling memory?
It depends on the platform. But many implementations of
'new' just use malloc internally.

: If someone has insufficient memory to run a big problem, do you think
: it makes any difference to use 'new' or 'malloc'?
No (except for rare cases where you may benefit from 'realloc',
which is only available with the latter).
Can you tell more about the problem you are trying to solve?
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Nov 9 '06 #2
Some library will overload operator new, then the great differences exist.

"Mohsen" <ja*******@gmail.com>
??????:11*********************@h54g2000cwb.googleg roups.com...
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen

Nov 9 '06 #3
"Mohsen" <ja*******@gmail.comwrote in message
news:11*********************@h54g2000cwb.googlegro ups.com...
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen
Typically, it wouldn't matter, as most default implementations of new use
malloc under the seams. However, you are free to create your own
implementation of new, in which case it could make a diffeence depending on
what you did (I could forsee someone using memory sticks).
Nov 9 '06 #4
Mohsen wrote:
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen
new crates objects.
malloc allocates bytes of memory.

New has a return type of something other than void*.
New can have the memory allocator swapped out (operator new overloaded)
New performs initialization of most types.
New performs "behind-the-scenes" types of initialization like
setting up run-time typing.
Nov 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: john smith | last post by:
Can someone please explain to me what is happening when I do a malloc(0). This is what I did. int* p = (int*)malloc(0); Then I printed the value of p and of course it was non-null. But...
34
by: Richard Hunt | last post by:
I'm sorry for asking such a silly question, but I can't quite get my head around malloc. Using gcc I have always programmed in a lax C/C++ hybrid (which I suppose is actually c++). But I have...
231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
20
by: spasmous | last post by:
main() { float * f; initialize_f(f); // ...use f for processing free(f); }
15
by: Martin Jørgensen | last post by:
Hi, I have a (bigger) program with about 15-30 malloc's in it (too big to post it here)... The last thing I tried today was to add yet another malloc **two_dimensional_data. But I found out that...
68
by: James Dow Allen | last post by:
The gcc compiler treats malloc() specially! I have no particular question, but it might be fun to hear from anyone who knows about gcc's special behavior. Some may find this post interesting;...
40
by: Why Tea | last post by:
What happens to the pointer below? SomeStruct *p; p = malloc(100*sizeof(SomeStruct)); /* without a cast */ return((void *)(p+1)); /* will the returned pointer point to the 2nd...
71
by: desktop | last post by:
I have read in Bjarne Stroustrup that using malloc and free should be avoided in C++ because they deal with uninitialized memory and one should instead use new and delete. But why is that a...
23
by: raphfrk | last post by:
I am having an issue with malloc and gcc. Is there something wrong with my code or is this a compiler bug ? I am running this program: #include <stdio.h> #include <stdlib.h> typedef...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.