diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-02-16 12:45:53 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-02-16 12:57:03 -0500 |
commit | 9acb85597f1223ac26a5b19a9345849c43d0ff54 (patch) | |
tree | 1c468fd79b52034d616a562d5a9f0ef0c96f3381 /src | |
parent | 3b7673388da3598933ae6c4f9fdc7c79dee05558 (diff) | |
download | postgresql-9acb85597f1223ac26a5b19a9345849c43d0ff54.tar.gz postgresql-9acb85597f1223ac26a5b19a9345849c43d0ff54.zip |
Add new function dsa_allocate0.
This does the same thing as dsa_allocate, except that the memory
is guaranteed to be zero-filled on return.
Dilip Kumar, adjusted by me.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/mmgr/dsa.c | 16 | ||||
-rw-r--r-- | src/include/utils/dsa.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c index 7dc43f1ea79..3eb3d4d9a4e 100644 --- a/src/backend/utils/mmgr/dsa.c +++ b/src/backend/utils/mmgr/dsa.c @@ -756,6 +756,22 @@ dsa_allocate(dsa_area *area, Size size) } /* + * As dsa_allocate, but zeroes the allocated memory. + */ +dsa_pointer +dsa_allocate0(dsa_area *area, Size size) +{ + dsa_pointer dp; + char *object; + + dp = dsa_allocate(area, size); + object = dsa_get_address(area, dp); + memset(object, 0, size); + + return dp; +} + +/* * Free memory obtained with dsa_allocate. */ void diff --git a/src/include/utils/dsa.h b/src/include/utils/dsa.h index bb634e77cda..3fd9bbd3a50 100644 --- a/src/include/utils/dsa.h +++ b/src/include/utils/dsa.h @@ -106,6 +106,7 @@ extern void dsa_set_size_limit(dsa_area *area, Size limit); extern Size dsa_minimum_size(void); extern dsa_handle dsa_get_handle(dsa_area *area); extern dsa_pointer dsa_allocate(dsa_area *area, Size size); +extern dsa_pointer dsa_allocate0(dsa_area *area, Size size); extern void dsa_free(dsa_area *area, dsa_pointer dp); extern void *dsa_get_address(dsa_area *area, dsa_pointer dp); extern void dsa_trim(dsa_area *area); |