CODING_STANDARDS addition re: emalloc
| From: | Jon Parise | Date: | Wed, 09 Oct 2002 02:14:00 +0000 |
| Subject: | CODING_STANDARDS addition re: emalloc | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-89259@lists.php.net to get a copy of this message | ||
Attached is a patch that adds a new item to CODING_STANDARDS that
suggests using emalloc() and friends over the standard C library
version. It also offers an explanation, courtesy of Rasmus' reply to
my earlier question on the subject.
If no one objects to the addition in principle or in wording, I'll
commit this in a few days.
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)
Index: CODING_STANDARDS =================================================================== RCS file: /repository/php4/CODING_STANDARDS,v retrieving revision 1.22 diff -u -r1.22 CODING_STANDARDS --- CODING_STANDARDS 9 Sep 2002 07:54:11 -0000 1.22 +++ CODING_STANDARDS 9 Oct 2002 02:09:46 -0000 @@ -122,6 +122,15 @@ existing. End users should use function_exists() to test for the existence of a function +[11] Prefer emalloc(), efree(), estrdup(), etc. to their standard C library + counterparts. These functions implement an internal "safety-net" + mechanism that ensures the deallocation of any unfreed memory at the + end of the request. They also provide useful allocation and overflow + information when running in debug mode. + + malloc() should only be used in instances where you need to allocate + memory that will be freed (via free()) inside of a third-party library. + Naming Conventions ------------------
Index: CODING_STANDARDS =================================================================== RCS file: /repository/php4/CODING_STANDARDS,v retrieving revision 1.22 diff -u -r1.22 CODING_STANDARDS --- CODING_STANDARDS 9 Sep 2002 07:54:11 -0000 1.22 +++ CODING_STANDARDS 9 Oct 2002 02:09:46 -0000 @@ -122,6 +122,15 @@ existing. End users should use function_exists() to test for the existence of a function +[11] Prefer emalloc(), efree(), estrdup(), etc. to their standard C library + counterparts. These functions implement an internal "safety-net" + mechanism that ensures the deallocation of any unfreed memory at the + end of the request. They also provide useful allocation and overflow + information when running in debug mode. + + malloc() should only be used in instances where you need to allocate + memory that will be freed (via free()) inside of a third-party library. + Naming Conventions ------------------