Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SdsMakeRoom always in DRAM #205

Open
wants to merge 1 commit into
base: 6.0-memkind_alloc_by_size
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void sdsclear(sds s) {
*
* Note: this does not change the *length* of the sds string as returned
* by sdslen(), but only the free buffer space we have. */
sds sdsMakeRoomFor(sds s, size_t addlen) {
static sds _sdsMakeRoomFor(sds s, size_t addlen, int on_dram) {
void *sh, *newsh;
size_t avail = sdsavail(s);
size_t len, newlen;
Expand Down Expand Up @@ -252,7 +252,8 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
} else {
/* Since the header size changes, need to move the string forward,
* and can't use realloc */
newsh = s_malloc(hdrlen+newlen+1);
newsh = (on_dram == SDS_DRAM_VARIANT) ? s_dram_malloc(hdrlen+newlen+1)
: s_malloc(hdrlen+newlen+1);
if (newsh == NULL) return NULL;
memcpy((char*)newsh+hdrlen, s, len+1);
s_free(sh);
Expand All @@ -264,6 +265,15 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
return s;
}

sds sdsMakeRoomFor(sds s, size_t addlen) {
return _sdsMakeRoomFor(s, addlen, SDS_GENERAL_VARIANT);
}

sds sdsDramMakeRoomFor(sds s, size_t addlen) {
return _sdsMakeRoomFor(s, addlen, SDS_DRAM_VARIANT);
}


/* Reallocate the sds string so that it has no free space at the end. The
* contained string remains not altered, but next concatenation operations
* will require a reallocation.
Expand Down
1 change: 1 addition & 0 deletions src/sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);

/* Low level functions exposed to the user API */
sds sdsMakeRoomFor(sds s, size_t addlen);
sds sdsDramMakeRoomFor(sds s, size_t addlen);
void sdsIncrLen(sds s, ssize_t incr);
sds sdsRemoveFreeSpace(sds s);
size_t sdsAllocSize(sds s);
Expand Down