You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-user@axis.apache.org by Shiraz Muthalif <sh...@opensource.lk> on 2004/07/24 11:52:01 UTC

Memory Allocation - Issues

Hi All,

I wish inform the Axis C++ community that I have been trying to replace
the memory allocation mechanism from C++ style to C style on the client
side code and any tool generated code however it has not been possible as
even though the code compiles the samples tend to fail. I came up with 2
reasons why this can not be done at the present time.

      • AS C++ is and object oriented language and supports concepts like
destructors and constructors the C programming language not being
object oriented does not support them. Therefore when we de-allocate
memory allocated by C++ code using C style “free” memory
de-allocation mechanism the destructors are not called.

The solution for the above problem might be to completely change the
memory allocation mechanism to C++ style memory allocation mechanism.
However there seems to be issues when we try to go for this solution.

      • When an array is de-serialized it uses C style memory allocation
mechanism in the present code and needs a memory “re-allocation”
mechanism for this purpose, C++ does not support “realloc” and if we
use “new” instead we have to allocate fresh memory blocks each time
we need to increase the array size. This can be more expensive than
using "realloc".

Hope this information is useful. Please feel free to send your comments or
suggestions regarding this issue.

Thanks and regards,

Shiraz.


RE: Memory Allocation - Issues

Posted by Susantha Kumara <su...@opensource.lk>.
> -----Original Message-----
> From: Samisa Abeysinghe [mailto:samisa_abeysinghe@yahoo.com]
> Sent: Wednesday, July 28, 2004 4:34 PM
> To: Apache AXIS C Developers List
> Subject: RE: Memory Allocation - Issues
> 
> --- Susantha Kumara <su...@opensource.lk> wrote:
> > Hi Shiraz,
> >
> > >       . AS C++ is and object oriented language and supports
concepts
> > like
> > > destructors and constructors the C programming language not being
> > > object oriented does not support them. Therefore when we
de-allocate
> > > memory allocated by C++ code using C style "free" memory
> > > de-allocation mechanism the destructors are not called.
> > >
> > > The solution for the above problem might be to completely change
the
> > > memory allocation mechanism to C++ style memory allocation
mechanism.
> > > However there seems to be issues when we try to go for this
solution.
> > >
> >
> > Our aim is to use one memory allocation mechanism. So inside the
Axis
> > Engine we have classes with constructors and destructors (some times
> > virtual destructors). So we need to use new/delete mechanism anyway.
So
> > the good idea to use the same new/delete mechanism to allocate user
> > types as well.
> >
> > >       . When an array is de-serialized it uses C style memory
> > allocation
> > > mechanism in the present code and needs a memory "re-allocation"
> > > mechanism for this purpose, C++ does not support "realloc" and if
we
> > > use "new" instead we have to allocate fresh memory blocks each
time
> > > we need to increase the array size. This can be more expensive
than
> > > using "realloc".
> >
> >
> > Even if using "new/memcpy/delete" instead of "realloc" might affect
> > performance.
> 
> How much? Any measures?

Never measured. If you measure it the results depend on the array size /
OS / Available physical memory in your machine / layout of allocated and
free memory areas in heap etc.
Scenario is that initial array size is 2 and you keep doubling it until
you exceed your array size. 

> 
> Samisa...
> 
> >
> > >
> > > Hope this information is useful. Please feel free to send your
> > comments or
> > > suggestions regarding this issue.
> > >
> > > Thanks and regards,
> > >
> > > Shiraz.
> >
> > Susantha.
> >
> >
> 
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail is new and improved - Check it out!
> http://promotions.yahoo.com/new_mail


RE: Memory Allocation - Issues

Posted by Samisa Abeysinghe <sa...@yahoo.com>.
--- Susantha Kumara <su...@opensource.lk> wrote:
> Hi Shiraz,
> 
> >       . AS C++ is and object oriented language and supports concepts
> like
> > destructors and constructors the C programming language not being
> > object oriented does not support them. Therefore when we de-allocate
> > memory allocated by C++ code using C style "free" memory
> > de-allocation mechanism the destructors are not called.
> > 
> > The solution for the above problem might be to completely change the
> > memory allocation mechanism to C++ style memory allocation mechanism.
> > However there seems to be issues when we try to go for this solution.
> > 
> 
> Our aim is to use one memory allocation mechanism. So inside the Axis
> Engine we have classes with constructors and destructors (some times
> virtual destructors). So we need to use new/delete mechanism anyway. So
> the good idea to use the same new/delete mechanism to allocate user
> types as well.
> 
> >       . When an array is de-serialized it uses C style memory
> allocation
> > mechanism in the present code and needs a memory "re-allocation"
> > mechanism for this purpose, C++ does not support "realloc" and if we
> > use "new" instead we have to allocate fresh memory blocks each time
> > we need to increase the array size. This can be more expensive than
> > using "realloc".
> 
> 
> Even if using "new/memcpy/delete" instead of "realloc" might affect
> performance. 

How much? Any measures?

Samisa...

> 
> > 
> > Hope this information is useful. Please feel free to send your
> comments or
> > suggestions regarding this issue.
> > 
> > Thanks and regards,
> > 
> > Shiraz.
> 
> Susantha.
> 
> 



		
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

RE: Memory Allocation - Issues

Posted by Susantha Kumara <su...@opensource.lk>.
Hi Shiraz,

>       . AS C++ is and object oriented language and supports concepts
like
> destructors and constructors the C programming language not being
> object oriented does not support them. Therefore when we de-allocate
> memory allocated by C++ code using C style "free" memory
> de-allocation mechanism the destructors are not called.
> 
> The solution for the above problem might be to completely change the
> memory allocation mechanism to C++ style memory allocation mechanism.
> However there seems to be issues when we try to go for this solution.
> 

Our aim is to use one memory allocation mechanism. So inside the Axis
Engine we have classes with constructors and destructors (some times
virtual destructors). So we need to use new/delete mechanism anyway. So
the good idea to use the same new/delete mechanism to allocate user
types as well.

>       . When an array is de-serialized it uses C style memory
allocation
> mechanism in the present code and needs a memory "re-allocation"
> mechanism for this purpose, C++ does not support "realloc" and if we
> use "new" instead we have to allocate fresh memory blocks each time
> we need to increase the array size. This can be more expensive than
> using "realloc".


Even if using "new/memcpy/delete" instead of "realloc" might affect
performance. We have no choice.

> 
> Hope this information is useful. Please feel free to send your
comments or
> suggestions regarding this issue.
> 
> Thanks and regards,
> 
> Shiraz.

Susantha.