I am using VS Code with the Microsoft C/C++ extension and intellisense gives me a weird error on something that otherwise works and compiles: #include <new> int main() { int *arr = new (std::nothrow) int[10]; return 0; } It marks new with function "operator new[]" cannot be called with the given argument list — argument ..
Category : allocation
I’m trying to implement my own math library, and I’m starting off with vectors. The idea is to give the class a pointer to an array of numbers, then copy the array and store it in the data address given by a private variable pointer. To begin with, I used alloca to try and free ..
Given a container v with v.size() == 3 and v.capacity() == 5, my understanding is that a call to v.shrink_to_fit() can be fulfilled and, if it is, it causes v.capacity() to become 3. However, this comes at the cost of a reallocation. Why? Isn’t it possible to free the unused memory without reallocating a chunk ..
const size_t size = 10000000; using T = unsigned short[]; vector<unique_ptr<T>> v; v.resize(size); for (size_t n = 0; n != size ; ++n) { v[n] = make_unique<T>(3); for (int i = 0; i!= 3; ++i) v[n][i] = rand(); } I want to measure how much memory it uses. What I expect: 10.000.000*(8+2*3) = 140.000.000 bytes. ..
I’m trying to use tracy (https://github.com/wolfpld/tracy) with CUDA With tracy, to measure memory usage you override operator new and operator delete like this: void* operator new(std::size_t count) { auto ptr = malloc(count); TracyAlloc(ptr, count); return ptr; } void operator delete(void* ptr) noexcept { TracyFree(ptr); free(ptr); } But when trying to use these with CUDA code ..
Why allocate() and deallocate() has not been called when using self-defined allocator with std::string? Here is the code snippet for demo(https://coliru.stacked-crooked.com/a/bcec030e8693f7ae): #include <cstring> #include <iostream> #include <limits> #define NOMINMAX #undef max template <typename T> class UntrackedAllocator { public: typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; ..
Should these member functions(i.e: max_size(), construct() and destroy()) be implemented when defining a STL allocator by myself with std=c++11 option? Are there some potential problems that I should be aware of when invoking the STL with the allocator without these aforementioned member functions? As per https://en.cppreference.com/w/cpp/memory/allocator, these member functions are deprecated in C++17 and removed ..
Should these member functions(i.e: max_size(), construct() and destroy()) be implemented when defining a STL allocator by myself with std=c++11 option? Are there some potential problems that I should be aware of when invoking the STL with the allocator without these aforementioned member functions? As per https://en.cppreference.com/w/cpp/memory/allocator, these member functions are deprecated in C++17 and removed ..
Should these member functions (i.e: max_size(), construct() and destroy()) be implemented when defining an allocator by myself with std=c++11 option? Are there some potential problems that I should be aware of when invoking the STL containers with the allocator without these aforementioned member functions? As per https://en.cppreference.com/w/cpp/memory/allocator, these member functions are deprecated in C++17 and ..
Is there a way to allocate uninitialized memory and then use it to construct objects without std::allocator? I looked into std::allocator’s sources and it just calls the ordinary operator new. When I try to do the same I get an error suggesting to use std::allocator. The same problem with object construction. std::construct_at works but when ..
Recent Comments