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
4 votes
3 answers
4k views

Doubly Linked List Implementation [C++]

C++ noob reporting. I'm working on implementing a doubly linked list using two separate classes: one class, called node, containing your standard doubly linked list ...
cmt_'s user avatar
  • 41
1 vote
1 answer
708 views

HTTP download with dynamic reallocation and retries

This code is for downloading a file via winhttp lib, It's invoked by StartDownload function which tries to download n times before returning false if maximum tries ...
randomdude's user avatar
2 votes
2 answers
175 views

Quick general purpose linked list in C

I want to use it when some function needs to return a list of something. Is it working as I think it should or is there undefined behavior somewhere? What I really tried to achieve is something like a ...
CorellianAle's user avatar
28 votes
5 answers
5k views

C++ Vector Clone

I'm learning C++, so I decided to make a simpler clone of std::vector. Concerns: I have seen people defining methods outside of the class, and only prototyping ...
internet_user's user avatar
9 votes
2 answers
6k views

Fast pool allocator for games in C++

I have implemented the following pool allocator in C++: ...
Peter Lenkefi's user avatar
5 votes
2 answers
458 views

Overriding operator delete/new to check correct pairs of (non-)array variants

A legacy project I am maintaining in my freetime uses overrides of operator delete / operator new. These overrides over-allocate ...
Zsar's user avatar
  • 151
3 votes
0 answers
315 views

C++ object pool using C memory pool as base

I started out with this question on Stack Overflow. I have since then gotten an official answer from the mbed developers that the MemoryPool that I was asking about only issued raw C malloc/free type ...
paulluap's user avatar
9 votes
4 answers
2k views

Populating a structure

I'm solving K&R exercise 1-13: Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation ...
user avatar
4 votes
1 answer
653 views

Fixed-Size Memory Pool with alignment

After taking a break and reviewing the comments on my first attempt at creating a fixed-size memory pool, this is my second attempt. The memory pool should allocate each block correctly aligned in ...
Acorn's user avatar
  • 283
5 votes
2 answers
550 views

A free-standing weak_ptr equivalent to handle lifetime of non-shared callback objects

I've been finding myself wanting the following pattern recently: ...
user avatar
3 votes
1 answer
239 views

Stack allocator and C11's alignment features

I am trying to write a custom stack allocator for a game I am working on. To deal with memory alignment, I am using C11's stdalign.h header; however, since I do not ...
strNOcat's user avatar
  • 131
5 votes
1 answer
2k views

dqueue - A dynamic FIFO queue library for C

This is the first draft of dqueue, a dynamic queue library written in C, with a sample program to demonstrate it. This is my first time writing any sort of library to be used as a generic subsection ...
jess's user avatar
  • 1,378
-1 votes
3 answers
105 views

Populate array with random numbers efficiently

I have an initial Excel workbook with about 100 000 rows. I put those rows into array and then use that array to create Client ...
Ans's user avatar
  • 121
12 votes
2 answers
2k views

Weapon and Hero classes

For me as a complete newbie to the world of C++, getters and setters are a rather confusing topic. There seems to be a wide range of opinions on what constitutes a sound use of getters and setters. In ...
Michael Langbein's user avatar
2 votes
1 answer
159 views

Private storage for at-rest data in VBA

One major annoyance in VBA programming is that it's hard to keep a secret secret. In this particular case, it's the ADODB.Connection. For reasons not germane to the ...
this's user avatar
  • 2,019
0 votes
1 answer
2k 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 ...
Ram Subramaniam's user avatar
1 vote
1 answer
3k views

C Implementation of dynamic mem allocation using first-fit algo

I have implemented malloc and free in C based on first-fit algo and using a circular linked list for free blocks of memory. It seems to be working based on the basic test in the main function. I would ...
Vikas Yadav's user avatar
2 votes
4 answers
5k views

Memory allocation for linked list in C

I am new to C and am writing a basic program to calculate the arithmetic sum of two numbers stored in a linked list. My main question is idiomatic memory management in C. The program below allocates ...
cm007's user avatar
  • 247
-3 votes
1 answer
7k views

Memory error in python [closed]

I am writing a code which returns something like 1^k + 2^k + 3^k......n-1 where k be any number.Below is my code.I am getting a memory error.How do I optimise it. Sample test case for wrong error: 1 ...
Leo B Jacob's user avatar
3 votes
1 answer
97 views

Recursion function subtracting accumulated percentage with <<-

I have a file with percentage of presence of micro-organisms but each category has the accumulation of percentages of the child categories. I designed a recursive function to subtract the proportion ...
llrs's user avatar
  • 273
6 votes
2 answers
2k views

Container for fast deletion and addition of elements

I need a container that is able to delete and add elements as fast as possible, without the need of reallocation that usually takes place when we push_back elements in an ...
Turms's user avatar
  • 215
5 votes
3 answers
2k views

Fastest FIFO with macros for use embedded devices

UPDATE (a year later) Since this post the code has turned into a small library called fifofast and is hosted on github under the MIT License. This note is meant for anyone who stumbled across this ...
nqtronix's user avatar
  • 161
-3 votes
2 answers
6k views

Working around a Segmentation Fault for reading Files in C [closed]

I am getting a segmentation fault on the below snippet, only when I go above a text file in the range of 80-100kb. It will read smaller files of text but otherwise ...
Computer's user avatar
3 votes
1 answer
1k views

Templated Game Resource Manager

After scanning some of the questions here about resource managers I've made some changes, and while it is much improved I still feel it's not quite up to snuff. It tried to make it work for all data ...
Eejin's user avatar
  • 175
2 votes
1 answer
1k views

Fixed-size C++ object pool, contiguous storage, O(1) random access, alloc and free. One header-only

I have implemented a rather simple object pool for the sake of entities in my game world, and it works quite well. Advantages: Elements stay in contiguous memory - can be iterated just like in an ...
Pythagoras of Samos's user avatar
2 votes
1 answer
505 views

C++ Policy-based object pool

Description This is an improved implementation for a previous post My goal was to implement a decent object pool using templates and policy based design. The object pool behaviour can be customized ...
amc176's user avatar
  • 345
7 votes
2 answers
1k views

Implementing a copy on write String class using reference counting in C++

I have tried to implement a copy on write string class with value semantics and reference counting. I wanted to support indexing, so I have overloaded the operator[] and to differentiate between the ...
sunil pai's user avatar
8 votes
3 answers
942 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....
user avatar
0 votes
1 answer
2k views

File upload in AngularJS causes browser out of memory error

I have an AngularJS code to perform upload of files. At first I thought it works OK but when I've tried to upload bigger files (e.g. 5 files, 10 MB each) then I saw that this code has very poor ...
Mariusz Ignatowicz's user avatar
1 vote
1 answer
489 views

Using mutable keyword to implement an owner-pointer class (C++03)

For a couple of days, I have been trying to implement an own templated class called owner_ptr (for my little project) whose instances has ownership over a ...
Gergely Tomcsányi's user avatar
5 votes
3 answers
486 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 <...
Gergely Tomcsányi's user avatar
4 votes
0 answers
420 views

Cleaning up memory after loading Access DB into a datagrid

I wrote an app that pulls a MS Access DB into a DataTable and then displays it into a WPF datagrid. The dialog window has a search button which calls on a class ...
Phexyaa's user avatar
  • 63
12 votes
4 answers
4k views

C++ Doubly Linked List Implementation

Does anyone have suggestions on how to improve this? Specifically: Am I passing and returning references correctly to prevent unnecessary copying? Am I using destructors and the delete keyword ...
user146276's user avatar
0 votes
1 answer
5k views

A factory with static objects or an enum with instance objects?

My application accepts different messages. A message is described by its schema. enum ...
Sam's user avatar
  • 179
5 votes
4 answers
360 views

Simple SingleLinkedList Implementation in C++

Below I have a very simple LinkedList implementation. I was wondering if there are any memory leak problems with this and if I used the pointers correctly. I just started practicing with C++ and ...
Kemal Tezer Dilsiz's user avatar
3 votes
0 answers
444 views

Applying Scikit-Learn Linear Kernel with a generator for low memory pressure

matrix = # a sparse matrix of TFIDF vectors - 28458x3218988 My aim was to create a similarity matrix comparing all documents to all documents using ...
James Allen-Robertson's user avatar
2 votes
1 answer
125 views

Unsafe collection which allows immutable access while also allowing push()

To get myself used to writing unsafe code, I wrote a collection which allows the user to keep immutable references to the elements of a vector while still being ...
lncr's user avatar
  • 125
2 votes
3 answers
147 views

Project Euler #12 in C (memory management)

I haven't written one bit of C code in well over a decade, being mostly in C#, Rust and Elixir. That being said I have a work reason to work in some C code (much to my dismay) and I'm trying to get ...
KallDrexx's user avatar
  • 211
3 votes
0 answers
636 views

Populate MongoDB with random documents using a Go channel

I recently created a small app in Go that generates random bson documents and insert them in a database (MongoDB). See this question for details. After doing some profiling, I realised that garbage ...
felix's user avatar
  • 588
2 votes
1 answer
2k views

Test code for custom malloc

I've been working on a custom malloc where the test code is the following. ...
Niklas Rosencrantz's user avatar
2 votes
0 answers
502 views

Partial file encryption with AES

Task is to encrypt part of the file using aes encryption algorithm. I did ...
Lolidze's user avatar
  • 201
3 votes
1 answer
1k views

Thread-safe Shared Pointer implementation in C

I've been working on a C project where I needed a small, thread-safe shared pointer, and so I wrote this implementation. It's primary use in the project is as a way of allowing multiple threads to ...
Ben Hollier's user avatar
1 vote
1 answer
917 views

MemoryError for a small-ish dataset with RandomForestClassifier()

I have a not-so-big dataset having 100,000 rows and 6k columns and I'm using the following code to fit a Random Forest to it: ...
Patthebug's user avatar
  • 195
1 vote
2 answers
175 views

A pointer that stores its size at the front

There are two main ways to keep the size of a pointer. One as just another variable along side: ...
Artyer's user avatar
  • 316
6 votes
1 answer
4k views

Apply the smallest possible datatype for each column in a pandas dataframe to reduce RAM use

This function is for Python Pandas users. I noticed a lot of RAM can be saved by applying smaller datatypes to columns. The function's input is a Pandas DataFrame. The function output is the compact ...
Arjan Groen's user avatar
3 votes
1 answer
143 views

Dynamic Allocation and Reallocation of Memory

This is a code snippet of a larger program. I tried to simplify it as much as possible. This code identifies certain particles and stores them in a list which corresponds to a certain processor. ...
Gilfoyle's user avatar
  • 1,125
3 votes
1 answer
571 views

Allocation and reallocation of memory

I am programming a parallel tree algorithm where I have to send data to other processors. The amount of data is not constant. Therefore I have to work with dynamic arrays using ...
Gilfoyle's user avatar
  • 1,125
6 votes
2 answers
199 views

"Safe" memory management

In order to concisify the handling of a failed call to malloc, realloc, or calloc, I have ...
Conor O'Brien's user avatar
25 votes
6 answers
6k views

C++ string operators

I'm trying to practice my C++ on my own; At the moment I'm trying to implement the concept of operator overloading making my own string class/function. I think I handled this correctly; the code ...
Dries Reyskens's user avatar
13 votes
1 answer
8k views

Resource Manager in C++ for Games

I'm currently writing a small game, needing some advice for things I could do better on this resource management system. Speed is not crucial, and I have no memory budget. The goal is to load and ...
K.K. Slider's user avatar

1
3 4
5
6 7
13