Hi,
What is the difference between new() and malloc()?
RS 16 6790
RS wrote: What is the difference between new() and malloc()?
'new' is the C++ way to create object in free store.
'mallow' is the C way to allocate some memory.
That's explained by lots of books. You can even google it.
Simply put, new is OOP, while malloc is not.
"RS" <rs@nospam.co m> дÈëÓʼþ news:76SOd.3582 25$Xk.263642@pd 7tw3no... Hi,
What is the difference between new() and malloc()?
RS
Victor Bazarov wrote: RS wrote:
What is the difference between new() and malloc()?
'new' is the C++ way to create object in free store. 'mallow' is the C way to allocate some memory.
You need to add malloc to your spell checker dictionary.
E. Robert Tisdale wrote: Victor Bazarov wrote:
RS wrote:
What is the difference between new() and malloc()?
'new' is the C++ way to create object in free store. 'mallow' is the C way to allocate some memory.
You need to add malloc to your spell checker dictionary.
No, I need to work shorter days. So do you, apparently.
In article <37************ *@individual.ne t>,
MatrixV <tr******@kcoll ege.com> wrote: That's explained by lots of books. You can even google it. Simply put, new is OOP, while malloc is not.
That's odd; I use malloc for OOP quite regularly.
Mind you, I do OOP in C quite regularly (for assorted reasons, most
of them actually reasonable), and I never use malloc when I'm actually
writing C++ code, whether I'm doing OOP or not...
dave
--
Dave Vandervies dj******@csclub .uwaterloo.ca
My personal best estimate is that 90% of existing C code is crap (F various VO
crap), and 90% of existing NotC code is crap too. (I expect this to be true of
non-existing code as well.) --Dimitri Mazuik in the scary devil monastery
Dave Vandervies wrote: [...] I never use malloc when I'm actually writing C++ code, whether I'm doing OOP or not...
Really? Why? What's so bad about 'malloc'? It is
often _the_ function to call if you overload the
operator new...
In article <EO************ *******@newsrea d1.mlpsca01.us. to.verio.net>,
Victor Bazarov <v.********@com Acast.net> wrote: Dave Vandervies wrote: [...] I never use malloc when I'm actually writing C++ code, whether I'm doing OOP or not...
Really? Why? What's so bad about 'malloc'? It is often _the_ function to call if you overload the operator new...
Usually, if I find myself wanting to overload the operator new, I soon
find myself deciding that the code is better written in C than in C++
anyways.
When I choose C++ over C, the reasons usually involve things like
letting the compiler handle resource management by running constructors
and destructors without me having to write the code to do it myself,
so using malloc instead of new kind of defeats the purpose.
(This probably has at least as much to do with the type of code I write
as with the characteristics of the two languages.)
dave
--
Dave Vandervies dj******@csclub .uwaterloo.ca
My personal best estimate is that 90% of existing C code is crap (F various VO
crap), and 90% of existing NotC code is crap too. (I expect this to be true of
non-existing code as well.) --Dimitri Mazuik in the scary devil monastery
"MatrixV" <tr******@kcoll ege.com> wrote in message news:<37******* ******@individu al.net>... That's explained by lots of books. You can even google it. Simply put, new is OOP, while malloc is not.
"RS" <rs@nospam.co m> дÈëÓʼþ news:76SOd.3582 25$Xk.263642@pd 7tw3no... Hi,
What is the difference between new() and malloc()?
RS
Hi,
using malloc following things are not possible,
-- calling constructor after allocating memory(new calls
constructor as well)
-- Type safety: (new returns a pointer of the right type)
-- Overridability: (new is an operator that can be overridden)
Thanks,
Basavaraj Kirunge
You though you are doing quite well, but you are not. As Mr. Kirunge said,
malloc can't do many things, it just alloc a memory space. Of course you can
implement new by malloc, and in fact that's the way it goes.
I suggest you to google it instead of asking here. I read a lot on this and
it's hard to put them all here.
"Dave Vandervies" <dj******@csclu b.uwaterloo.ca> ????
news:cu******** **@rumours.uwat erloo.ca... In article <37************ *@individual.ne t>, MatrixV <tr******@kcoll ege.com> wrote:That's explained by lots of books. You can even google it. Simply put, new is OOP, while malloc is not. That's odd; I use malloc for OOP quite regularly.
Mind you, I do OOP in C quite regularly (for assorted reasons, most of them actually reasonable), and I never use malloc when I'm actually writing C++ code, whether I'm doing OOP or not...
dave
-- Dave Vandervies dj******@csclub .uwaterloo.ca My personal best estimate is that 90% of existing C code is crap (F
various VO crap), and 90% of existing NotC code is crap too. (I expect this to be
true of non-existing code as well.) --Dimitri Mazuik in the scary devil
monastery This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: wwj |
last post by:
Hi ,all
I want to know the difference between char a and char *p=new
char and the difference between the heap and the stack ,and if the
char a is corresponding to the stack in MEMORY,and char *p=new
char is corresponding to the heap of MEMORY.
Give me some hint.
THANK YOU.
|
by: Mohanasundaram |
last post by:
Hi All,
What is the difference between malloc and calloc other than the
point that calloc will initialize the memory to all zeros? This was an
interview question for me. All the books and references that I have
come across tells that calloc initialize the memory to all zeros. In
Herbert Shiltd's C/C++ reference I found that calloc returns a pointer
to an array. I want to understand in what way the memory returned by
malloc and calloc...
|
by: Chris |
last post by:
This is the code:
######################
#include <stdlib.h>
using namespace std;
class intlist {
unsigned int length;
int * list;
public:
intlist() {
|
by: neilcancer |
last post by:
i come from china,and i'm sorry that my english is very poor.
now i'm studing data structure and i met some problem about c language.
could you tell me what will happen after i use free()? i mean once i
use free() on a pointer,what will the pointer points to ?
for example:
#include<stdio.h>
|
by: manish sahu |
last post by:
difference between calloc() and malloc()
| |
by: Pranav |
last post by:
class just{
public :
int x;
just(){ x=1234; }
just(int i){ x = i;}
~just(){ cout << " Here We Are\n" ;}
};
int main()
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |