All Questions
Tagged with c++ memory-management
260
questions
-4
votes
0
answers
50
views
Tetris C++ Troubles with memory leaks | code provided [closed]
Memory Loss in My Tetris Game 😓
Hey everyone,
I'm pretty new to C++ and this is my first post on Code Review, so I really appreciate any help all of you can provide. I've been working on a Tetris ...
0
votes
0
answers
31
views
Presence of UB and memory usage of a std::array initialization: version with temporary array on heap
I proposed several techniques to answer to https://stackoverflow.com/q/78672409/21691539.
A classical way to answer would be to use std::index_sequence-based ...
3
votes
1
answer
221
views
Presence of UB and memory usage of a std::array initialization
I proposed several techniques to answer to https://stackoverflow.com/q/78672409/21691539.
A classical way to answer would be to use std::index_sequence-based ...
4
votes
2
answers
899
views
OpenGL: Freeing allocated memory
Here's a snippet of my code. I have a Button structure made up by 2 Figure structures, which contains vertices, colors and the relative VBOs and VAO.
I have a function to allocate the memory and one ...
2
votes
1
answer
80
views
Generic container wrapper type with a default underlying buffer (2nd rev)
This is a revision of the previous question. I was told to ask an additional question with more context for the modified code to be reviewed.
The changes:
changed from ...
5
votes
1
answer
295
views
Generic container wrapper type with a default underlying buffer
I've come up with a type that allows me to encapsulate any container class (that supports std::pmr::polymorphic_allocator<T>) with a buffer and a memory ...
3
votes
1
answer
146
views
initializing a timezone database and getting all timezone names (before main())
I have written the below small program that tries to initialize a tzdb before the main() runs. So once the main function runs, it checks the two global variables (...
4
votes
1
answer
167
views
Track and trace allocations
When testing or debugging allocator-aware objects, it can be useful to provide allocators that can provide insight into how they get called. The Tracing_alloc from ...
4
votes
2
answers
254
views
C++ heap allocator using an explicit free list
Description
I've written a heap allocator in C++ using an explicit free list for organization. I've also written a series of unit tests and a microbenchmark using Catch2. At time of writing I've ...
2
votes
0
answers
48
views
Reusable storage for array of objects V4
Here is a thirdfollow up on Reusable storage for array of objects, Reusable storage for array of objects V2 and Reusable storage for array of objects V3, taking into account the provided answers.
The ...
1
vote
1
answer
48
views
Reusable storage for array of objects V3
Here is a second follow up on Reusable storage for array of objects and Reusable storage for array of objects V2, taking into account the provided answers.
The following code should be compliant at ...
3
votes
1
answer
66
views
Reusable storage for array of objects V2
Here is a follow up on Reusable storage for array of objects, taking into account the provided answers.
The following code should be compliant at least with gcc, <...
4
votes
2
answers
487
views
Reusable storage for array of objects
My goal is to have a memory pool non-template class that is used to store arrays of objects.
The same memory pool object must be reusable for a different array (difference size, different type and/or ...
2
votes
1
answer
96
views
Yet another std::unique_ptr implementation
I know I haven't implemented many methods, and haven't specialized it for T[], but I just want to see if what I coded is good or bad.
...
7
votes
2
answers
203
views
shared_ptr implementation code - first cut
I've written an implementation of shared_ptr. It doesn't support weak_ptr (yet) but below is the code. I'd appreciate any feedback, comments.
...
-1
votes
1
answer
289
views
Copying allocated data into std::map in a smart way [closed]
I come across a problem and I solved it. The solution works but I have some feelings that there is something wrong with my solution/code.
To be clear, let's assume that cars on the race track transmit
...
6
votes
3
answers
2k
views
Implementation of a shared pointer constructors and destructor
I am writing my simple shared pointer. I am asking to review existing functions (understand that my implementations is not full, e.g now operator*)
Review please ...
0
votes
1
answer
155
views
Multiple containers share a single memory resource
In my project, I'm trying to use the std::pmr allocator and monotonic_buffer_resource. I'm using vector in various classes, and ...
5
votes
4
answers
2k
views
StringPool in C++
I wrote a simple string pool for my compiler in C++ and want to hear your thoughts on its design.
String pool has 2 functions: intern and ...
0
votes
1
answer
545
views
Count the number of objects created statically and dynamically in C++
I have written below program to count the number of static and dynamically created object of the class.
...
4
votes
1
answer
770
views
C++ disk-file memory resource
After writing a C++ simulator for malloc() and free(), (C++ imitation of glibc malloc(), free()),
I thought: "My simulator ...
10
votes
1
answer
263
views
C++ imitation of glibc malloc(), free()
I wrote a C++ simulator that performs algorithms for glibc malloc() and free().
The core logic is basically the same, with the ...
1
vote
1
answer
162
views
C++ - Memory allocation utility functions. Is there memory leakage here?
I am quite new at C++ and I really wanna learn how to work with allocating memory.
So I have created some utility functions. I am aware that C++ uses new and ...
1
vote
2
answers
300
views
Improvement suggestions to my shared_ptr and weak_ptr implementations
Below is the entire code. I appreciate if, someone with more C++ experience can suggest if this can be improved further and if you notice any issues.
controlblock.hpp
...
1
vote
1
answer
248
views
C++ intializing and saving mp4 ftyp box struct byte by byte
I'm unsure whether the way I'm performing initialization is recommended, and whether there is a simpler way to save out a struct like the one I'm using. The main points of feedback I'm looking for are ...
1
vote
1
answer
359
views
C++ RAII helper classes for malloc arrays and files
I'm going to use these classes in a program I'm working on, so I want to see if they're correct or could be improved.
https://pastebin.com/qx7ccteT
...
3
votes
1
answer
2k
views
C++ thread-safe object pool
This is a modern C++ implementation of a thread-safe memory pool -- I want to make sure I am solving the critical section problem correctly (no deadlocks, starvation, bounded waiting) and I am getting ...
6
votes
4
answers
713
views
Simple Singly-Linked List class
Decided to write something simple and came up with idea to write simple single linked list in C++ to improve my knowledge about pointers and memory management in C++, and wrote this:
...
2
votes
3
answers
350
views
Fixed-size memory allocator
I've been trying to implement a simple Boost PMR allocator that has a fixed amount of memory. My first implementation (which can be found here) had undefined behavior and did not handle memory ...
5
votes
2
answers
836
views
C++ Garbage Collector - Simple Automatic Memory Management
I made a general smart pointer which fixes the problems of loops between std::shared_ptr's. While use is simple, I feel that my code is inefficient and clumsy. Here ...
4
votes
1
answer
961
views
C++ : Allocator for fixed size object
I'm reading "Modern C++ Design" (A. Alexandrescu, 2002). The author said "the standard memory allocator is awful for small objects", but it has been two decades after the book has ...
6
votes
3
answers
2k
views
Dynamic array implementation using C++
I implemented a basic dynamic array using C++.
When deleting an element and shifting the others, the last element will be twice repeated (the original still exists after copying). I want to avoid ...
0
votes
1
answer
750
views
Writing a buffer that takes a header and a variable number of packets and makes a payload [closed]
I'm writing this as an exercise. I would probably use a vector as a buffer internally (the extra capacity pointer overhead is not important enough). Primarily it's an exercise in writing copy/move ...
6
votes
4
answers
1k
views
Packing and unpacking values in a buffer
I have to deal with raw memory manipulation. For that I wrote a function which stores data one after another, and another function which reads this data and stores it into variables.
More precisely:
<...
2
votes
0
answers
101
views
Dynamic heterogeneous container
I want to have dynamic continuous block of memory for different types, that inherit from single base class. I've written structure for that purpose. I know I play with a fire here, but I would like to ...
2
votes
1
answer
446
views
4
votes
2
answers
567
views
"observer pointer" meant to stay updated when the pointed object is moved in memory
I wasn't sure about how to name it, maybe "follow_ptr", "self_updating_ptr", or "stalking_ptr" or something on those lines. For now it's called Identifier.
What I'm ...
11
votes
4
answers
4k
views
C++ dynamic array implementation
As a C++ beginner coming from Java, I have become increasingly confused on the topic of memory management and how to avoid memory leaks. Is the code below risking a memory leak that I'm not currently ...
0
votes
1
answer
554
views
Vector Implementation C++ using RAII
I have attempted to implement a similar version of the STL Vector; several functions are missing but I'd like a few words of advice on whether I am indeed on the right track or whether I should change ...
9
votes
3
answers
5k
views
A Tic Tac Toe game in C++
I am a beginner programmer and have made a tic tac toe program in c++. I need some help with my memory management can anyone review and help me. This is my code
...
4
votes
1
answer
117
views
Matrix template Class
This is my 2nd shot at dynamic memory allocation. This project is for practice purposes. So many things were considered whilst writing this minimal project.
I considered using placement new to ...
0
votes
1
answer
94
views
Simple C++ Dynamicly allocated Matrix with only one memory allocation [closed]
I was bothered with existing matrix allocation methods that take variable rows and columns, so I made a small class that only needs one memory allocation.
...
3
votes
1
answer
2k
views
A custom memory allocator in c++
Recently I became interested in implementing a FORTH language interpreter. That led me to read about memory models etc.
which led me to write this custom memory allocator in c++. It's very dumb as ...
4
votes
1
answer
716
views
slab malloc/free implementation
I'm trying to implment memory allocator guided by this tutorial. I used a mix of Next-fit search and Segregated-list search.
There are multiple slabs of different sizes (a slab is contagious blocks of ...
11
votes
1
answer
1k
views
Customization of memory class C++
I have implemented a customized memory allocation class template for an assignment. Codes are commented; Hopefully it's clear. I would love to know if there is any way to make the code more optimized.
...
2
votes
1
answer
55
views
Proper way of deallocating memory in SLL?
So I'm making my own singly linked list class, with methods that you'd expect such as remove() and insert(). I don't use ...
4
votes
1
answer
277
views
C++ Dynamic Array Class Testing
I'm creating a basic Dynamic Array class in C++, and I'd like to know if there are any bugs/memory leaks I haven't noticed yet.
dyn_arr.h :
...
1
vote
1
answer
151
views
A Pool-based Memory Management
I wrote a memory management class that is supposed to be used in a game.
I decided to use "Blocks" as an in-code representation.
It is written in MSVC++ and is currently not meant for ...
4
votes
1
answer
88
views
protein sequence translator using basic text manipulation
As an old COBOL coder, all this OOP stuff is foriegn. Would someone please take a look at this program? I'm looking for suggestions for ways to improve this program. While it works, I'm sure there's ...
2
votes
1
answer
98
views
c++ new-handler
I had just put together my first public project: simple(sane) new-handler for c++.
It allocates some reserved memory on start up, then releases it piece by piece. It may also raise a signal when each ...