This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about "new" operator in C++ and "malloc()" function in C. Thanks a lot


"QiangHuang" <jameshq@liverpool.ac.uk> writes:

> Dear all:
>        I have this question in mind for a while and I still can't figure it
> out. Hope somebody can share me some idea on this question. Thanks a lot.
> 
> Question 1:
> When using "new" operator in C++ for building eCOS application, no
> supporting package is needed while for using "malloc()" function, supporting
> package "memalloc" has to be added for building the eCOS library. Those two
> are all for memory allocation, so I wonder why "new" doesn't need any other
> supporting package while "malloc" does. (Can I guess the reason that: "new"
> is a operator, which has been implemented by the C++ compiler while for
> "malloc()" is a function, which will need lower level(system related)
> function support (from some other library, stdlib?)? )

If new is being used to allocate memory, then it needs exactly the
same support as malloc(). It just calls malloc() to do the
allocation. However, in some places in eCos we use a "placement new"
where the memory to be used is passed in as an argument to new. This
is done mainly so that constructors can get called correctly, there is
no need for extra support.

> 
> Question 2:
> When compiling/linking a 'C' eCOS application "-nostdlib" need to be
> suppiled, but if for 'C++' eCOS appliation do I need to supply any other
> directive? Or "-nostdlib" is applied for both 'C' and "C++" built eCOS
> appliation (Does this means we can just use C/C++ built in operator for
> building eCOS appliation not any other supporting functions?)?

We currently don't support any of the C++ runtime library routines. To
do this properly would also need a reorganization of the C library to
abstract out common code and preserve the expected relationships
between functions. Only functions/operators that are defined as part
of the language (like new and delete) are currently supported.

-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com      The eCos and RedBoot experts


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]