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

New Allocator #621

Draft
wants to merge 10 commits into
base: BANN_save_load_one_file
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 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
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"files.associations": {
"charconv": "cpp",
"xmemory": "cpp",
"array": "cpp",
"deque": "cpp",
"format": "cpp",
"initializer_list": "cpp",
"list": "cpp",
"queue": "cpp",
"random": "cpp",
"stack": "cpp",
"utility": "cpp",
"vector": "cpp",
"xhash": "cpp",
"xstring": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"ostream": "cpp",
"iostream": "cpp"
}
}
22 changes: 19 additions & 3 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ inline void alloc_aligned(void **ptr, size_t size, size_t align)
#ifndef _WINDOWS
*ptr = ::aligned_alloc(align, size);
#else
*ptr = ::_aligned_malloc(size, align); // note the swapped arguments!
#ifdef EXEC_ENV_OLS
*ptr = static_cast<void *>(operator new(size, std::align_val_t(align)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the word "operator" here? If not can we just do:

*ptr = static_cast<void *>(new(size, std::align_val_t(align)));

#else
*ptr = ::_aligned_malloc(size, align); // note the swapped arguments!
#endif
#endif
if (*ptr == nullptr)
report_memory_allocation_failure();
Expand All @@ -274,7 +278,15 @@ inline void realloc_aligned(void **ptr, size_t size, size_t align)
if (IS_ALIGNED(size, align) == 0)
report_misalignment_of_requested_size(align);
#ifdef _WINDOWS
*ptr = ::_aligned_realloc(*ptr, size, align);
#ifdef EXEC_ENV_OLS
void *newptr;
alloc_aligned(&newptr, size, align);
std::memcpy(newptr, *ptr, size);
delete ptr;
*ptr = newptr;
#else
*ptr = ::_aligned_realloc(*ptr, size, align);
#endif
#else
diskann::cerr << "No aligned realloc on GCC. Must malloc and mem_align, "
"left it out for now."
Expand Down Expand Up @@ -302,7 +314,11 @@ inline void aligned_free(void *ptr)
#ifndef _WINDOWS
free(ptr);
#else
::_aligned_free(ptr);
#ifdef EXEC_ENV_OLS
delete ptr;
#else
::_aligned_free(ptr);
#endif
#endif
}

Expand Down
Loading