This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Replacing malloc with alloca.
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Ajit Kumar Agarwal <ajit dot kumar dot agarwal at xilinx dot com>
- Cc: Jeff Law <law at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, "gcc\ at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Vinod Kathail <vinodk at xilinx dot com>, Shail Aditya Gupta <shailadi at xilinx dot com>, Vidhumouli Hunsigida <vidhum at xilinx dot com>, "Nagaraju Mekala" <nmekala at xilinx dot com>
- Date: Sun, 13 Sep 2015 20:28:53 +0200
- Subject: Re: Replacing malloc with alloca.
- Authentication-results: sourceware.org; auth=none
- References: <37378DC5BCD0EE48BA4B082E0B55DFAA42990090 at XAP-PVEXMBX02 dot xlnx dot xilinx dot com>
* Ajit Kumar Agarwal:
> The replacement of malloc with alloca can be done on the following
> analysis.
>
> If the lifetime of an object does not stretch beyond the immediate
> scope. In such cases the malloc can be replaced with alloca. This
> increases the performance to a great extent.
You also need to make sure that the object is small (less than a page)
and that there is no deep recursion going on. Otherwise, the program
may no longer work after the transformation with real-world restricted
stack sizes. It may even end up with additional security issues.