Questions tagged [memory-management]

Memory management is the act of managing computer memory by allocating portions of memory to programs as well as freeing memory so that it can be re-used.

Filter by
Sorted by
Tagged with
24
votes
1answer
19k views

Efficient smart pointer implementation in C++

The idea behind this is mainly educational but I might even consider using it in reality if turns out to be good. Here's my first try at implementing smart pointers: ...
29
votes
1answer
3k views

Yet another 'any' class implementation, named 'some'

This is a follow-up of 'any' class implementation. After posting my answer, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended up in some ...
8
votes
2answers
18k views

STL Stack Implementation

I implemented std::stack from the STL for deeper understanding of the language and memory since I still am only a beginner. I implemented the stack using a singly ...
8
votes
3answers
5k views

Simple Pool Allocator

This is a simple pool allocator, based (to at least some degree) on a previous answer. The basic idea is pretty simple: allow a user to allocate objects of some type quickly (in relatively large ...
7
votes
3answers
479 views

Non-fragmenting pool allocator

This is a fairly straightforward object allocator/factory, which sets up a stack of freed nodes as a linked list in the unused part of the storage. I would appreciate any and all feedback you may have....
5
votes
4answers
6k views

Texture managing

I'm new to C++ and SDL, and I've written a Texture manager class whose purpose is to help me manage sprites and other textures. I have a ...
15
votes
1answer
31k views

Alternative to setInterval and setTimeout

JavaScript's setTimeout() and setInterval() are evil and not precise: Both functions have a delay of a varying quantity of ...
11
votes
2answers
1k views

Implementation of a lock-free fixed-sized allocator

This question now has a follow-up: Implementation of a lock-free fixed-sized allocator - follow-up - with commented code I've tried implementing a lock-free fixed-size allocator while trying to ...
11
votes
3answers
4k views

Structure to ByteArray Extension

I have a need to turn various structures into byte arrays to be sent over serial port to another machine. I created generic extensions to turn any structure into a byte array and from a byte array ...
10
votes
4answers
2k views

Simple key-value store in C, take 2

Followup to Simple key-value store in C. Response to previous reviews You may want to hide the KVSstore structure Done. Add a comparison function pointer to KVSstore. If this pointer is null, ...
9
votes
3answers
31k views

Implementing an ArrayList

I implemented ArrayList functionality in C as follows: ...
4
votes
1answer
4k views

Vigenère cipher in C

For my second major project in C, I decided to write an implementation of the Vigenère cipher in C. My program uses command line options (optarg) and can read from both a file or from a string ...
12
votes
4answers
329 views

Bare-bones string library

After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own. This is a simple dynamic-string library ...
10
votes
5answers
1k views

Static factory function and lifetime

I'm trying to teach myself C++ at the moment, after years of C# and other managed languages. The class in question is a Level in a game, and the idea is to ...
7
votes
1answer
2k views

Hashing a SecureString using Cryptography Next Generation

Goal: I needed to calculate the salted hash of a password, where the password is stored as a SecureString. There doesn't seem to be much .NET framework support for SecureString. In particular, none ...
5
votes
4answers
2k views

ADT stack with a dynamic array

I'm starting to learn about data structures and coding in C. The stack is the simplest of all data structures so I'm trying to implement an ADT stack with dynamically allocated array in C. This ...
4
votes
2answers
4k views

Simple C++ object pool

I am studying computer science and just for the sake of practise I thought of implementing an object pool. This is my first implementation, it is simple and works correctly, but I would love any ...
4
votes
1answer
471 views

Iterative Red-Black Tree (dynamic stack)

I've completely reworked the previous code, posted here, so that it is a bit more correct regarding dynamic memory management, and also a bit more true to the object-oriented paradigm. ...
3
votes
1answer
1k views

Generic Graph Abstract Data Type Implementation in C++

Today I tried to code up a generic graph abstract data type in C++. Precisely, I implemented the adjacency list data structure for a generic graph type. I think it seems to work with different type ...
2
votes
0answers
262 views

Implementation of a lock-free fixed-sized allocator - follow-up - with commented code

The following implementation of a lock-free fixed-size allocator is a follow-up of: Implementation of a lock-free fixed-sized allocator §1 - Introduction The purpose is self-learning of atomic ...
2
votes
1answer
1k views

Vigenere Cipher in C

I'm going through CS50 and one of the problem sets was to implement a vigenere cipher. I have had some previous classroom experience with C before CS50, but still consider myself a beginner. The ...
11
votes
1answer
91 views

Longest lines using priority queue

Inspired by a comment on this question, I thought I'd exercise my C skills by implementing something like it using a priority queue. The idea is to be able to invoke the program like this: ./...
7
votes
2answers
8k views

Simple key-value store in C

I needed a simple key-value store. Here's what I came up with. Usage Use kvs_create and kvs_destroy to create stores and clean ...
6
votes
1answer
316 views

Locating the largest Collatz Sequence with memoization

Inspired by this question I wrote a memoized form of the collatz sequence calculator. The idea was to cache the sequence lengths for as many sequences as possible, from 0 to some value. I managed to (...
6
votes
5answers
1k views

Macro for allocation in C

As we all know, the syntax of allocating memory is a bit clunky in C. The recommended way is: int *p; int n=10; p = malloc(n*sizeof *p); You can use ...
6
votes
1answer
184 views

Pool allocator for a scripting language parser

At the moment I'm writing a parser and interpreter for a custom scripting language, to learn more about the basic concepts involved and to get more familiar with tools like ...
5
votes
3answers
1k views

Are these memory-allocation wrapper functions kosher with all C compilers?

I have never been entirely comfortable using malloc() and free() directly. For one thing, 99% of the time that I would like to ...
5
votes
3answers
373 views

Inheriting from std::auto_ptr to support deletion of allocated arrays in C++98/C++03

[EDIT: Thanks for your opinions. I think this topic is discussed enough. Since std::auto_ptr is removed from C++17, I decided to drop the idea of inheriting from <...
5
votes
2answers
2k views

Adding two BigInts using linked lists in C

While trying to learn more about linked lists, I thought I should try the exercise of reading two BigInts from an input file and then adding them up. My strategy was to store the two numbers in two ...
4
votes
2answers
1k views

Memory management for Red-Black Tree

I've written this program yesterday, and I was reminded why I dreaded C++ before turning to Java: pointers and associated terms (like destructors, initializations and copy/move constructors) are ...
4
votes
2answers
288 views

Python algorithm mimicking mark/sweep garbage collection

I don't have much experience with Python and would love some feedback on my implementation of this program. I am given a file with an integer representing a number of memory-cells, followed by a list ...
4
votes
1answer
498 views

Template double ended queue (deque) implementation using dynamic allocation C++

I have written my own deque class to get a better grasp of C++ pointers and memory management. The following code is part of a larger 2D isometric game I am developing. It compiles and runs fine using ...
3
votes
0answers
82 views

A fixed-size dynamic array

Background I implemented the historic std::dynarray according to the specification under the name dynamic_array in C++17. ...
2
votes
1answer
78 views

Singly linked list in pure C - follow-up

This is an update for this post. I fixed all style-issues from the comments, but still have a few questions left: Someone commented that my last post contained too many functions, which could be ...
2
votes
2answers
1k views

Using std::vectors to store textures

I need to write a TextureManager class which stores Texture objects; the problem is I'm using an ...
2
votes
3answers
136 views

Singly Linked List in pure C

I recently learned about linked lists and here is my first try to write one in C. I know it's a lot of code, but I hope someone takes a look. Any tips memory allocation and improvements are welcome. ...
2
votes
2answers
739 views

Creating an optimized, fully functional TextureManager in SDL

After I've discussed pointer semantics with Loki Astari previously, I finally managed to code the TextureManager class using auto_pointers. But the problem is that ...
2
votes
1answer
759 views

Test code for custom malloc

I've been working on a custom malloc where the test code is the following. ...
1
vote
2answers
201 views

Massive file sorting algorithm

I was trying to sort a massive file of successive chars in C. I did some research and found a few file sorting algorithms that look the same. Their main idea is to read an amount of data to memory, ...
1
vote
1answer
480 views

Working C code dealing with lists: problem with memory leak

I have written a working code that generates a simple linked list of dates and associated holidays. I realize that I have a problem with memory leaking as I copy lists repeatedly, so I wrote a ...
1
vote
0answers
103 views

Helper class for accessing blobs and mmap memory - follow up

This class was inspired from Microsoft's array_view. It intended to use with mmap-ed memory for easily check bounds and so on. I probably will need to throw exceptions, but this is not my usual way ...
0
votes
1answer
797 views

Implement a working Vending machine [closed]

Task: Design a vending machine which does the following: Accepts coins of 1, 5, 10, 25, 50 cents or notes of 1 and 2 User selections: Candy, snacks, nuts, Coke, Pepsi and soda ...