[Asterisk-code-review] vector: Add AST_VECTOR_COMPACT() to reclaim wasted space (...asterisk[13])
Kevin Harwell
asteriskteam at digium.com
Fri Mar 15 13:12:17 CDT 2019
Kevin Harwell has posted comments on this change. ( https://gerrit.asterisk.org/c/asterisk/+/11150 )
Change subject: vector: Add AST_VECTOR_COMPACT() to reclaim wasted space
......................................................................
Patch Set 1:
(1 comment)
https://gerrit.asterisk.org/#/c/11150/1/include/asterisk/vector.h
File include/asterisk/vector.h:
https://gerrit.asterisk.org/#/c/11150/1/include/asterisk/vector.h@604
PS1, Line 604: size_t new_max = (vec)->current; \
: typeof((vec)->elems) new_elems = ast_calloc(1, \
: new_max * sizeof(*new_elems)); \
: if (new_elems) { \
: if ((vec)->elems) { \
: memcpy(new_elems, (vec)->elems, \
: (vec)->current * sizeof(*new_elems)); \
: ast_free((vec)->elems); \
: } \
: (vec)->elems = new_elems; \
: (vec)->max = new_max; \
: } else { \
: res = -1; \
: break; \
: } \
: }
Can you just use realloc here instead? Best case scenario the rest gets marked as usuable by malloc and no new memory gets created, thus avoiding the copy (I *think*)?
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11150
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I9711daa0fe01783fc6f04c5710eba84f2676d7b9
Gerrit-Change-Number: 11150
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-Comment-Date: Fri, 15 Mar 2019 18:12:17 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190315/8b56af64/attachment-0001.html>
More information about the asterisk-code-review
mailing list