Questions tagged [memory-optimization]
Memory Optimization is a subset of Optimization: it is the goal of reducing the memory consumption (the amount of memory used during compile or run time) of your program or of a specific algorithm
240 questions
5
votes
2
answers
229
views
LeetCode Number 416: Partition Equal Subset Sum
Problem: MLE
I am confused as to why the LeetCode judge reports Memory Limit Exceeded when my solution looks close to the editorial solution. I not too familiar with ...
7
votes
1
answer
342
views
Robin Hood Hash Table
The following code comes from an intrusive container library I am working on in C23. So far, it works correctly due to extensive testing and sample programs I have written with it. I have implemented ...
3
votes
2
answers
166
views
Running yolov to detect class on many files in-memory accumulate RAM on Google Colab T4 GPU
I have thousands of files and I am detecting with YOLOV some classes on them with my own model file. My files are inside a zip file.
I must usually extracting json files which have vector data, then ...
8
votes
2
answers
282
views
Leetcode 93: Restore IP Addresses (C version)
This is posted in response to this request made in a discussion of my "C-ish" answer to a recent Code Review question regarding a Python solution to a Leetcode challenge. It was reported ...
11
votes
4
answers
2k
views
Leetcode 93: Restore IP Addresses
(Source: Leetcode 93: Restore IP Addresses [Medium])(Topics: [String] [Backtracking])
The problem is as follows:
Definition: A valid IP address is defined to consist of exactly four integers ...
6
votes
4
answers
1k
views
Custom Iterator for Processing Large Files
I frequently work with large files and implemented a custom iterator to process these files efficiently while minimizing memory usage. The iterator reads each line from a file, parses it into a ...
5
votes
1
answer
220
views
Memory-optimizing arduino code to be able to print all files from SD card
I started an Arduino project that could execute instructions from an SD card file on the screen. I managed to do it, but another problem appeared: I can't print all the files from the SD card to the ...
2
votes
1
answer
115
views
Check which sinks are connected in the pipe system using Python
It would be very helpful to me as a beginner if I could get feedback on my code, specifically about the efficiency of algorithm used and potential improvements in code quality.
Code context:
There is ...
5
votes
3
answers
307
views
HackerRank, Haskell simple "compression" algorithm
The question asked is very straight-forward and is simple enough to solve. What I am looking for is that hopefully I can get some understanding for using the constructs and built-ins of the Haskell ...
4
votes
2
answers
86
views
Optimizing a Function to Generate a Row of Consecutive Odd Numbers in a Triangle
I've written a JavaScript function that generates a row of consecutive odd numbers in a triangle. The triangle looks like this:
...
2
votes
1
answer
123
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 ...
4
votes
1
answer
122
views
Autocompletion trie for English words in zig
I am trying to write a program that creates a Trie from a list of all English words, and then when run provides completions for a given prefix. Basically for each node I allocate a list of 255 null ...
5
votes
4
answers
2k
views
Optimized Python Solution for Determining if an Array Contains All Possibilities
Problem:
You have been tasked with writing a method named is_all_possibilities (or IsAllPossibilities, as per your preference) ...
3
votes
1
answer
89
views
A collection based on a bitset to store a set of unique integers from a given range (rev. 3)
All right, let's do this one last time.
This is continuation of this review.
I applied most of the proposed changes, making interface of my container very close to that of ...
4
votes
1
answer
125
views
A collection based on a bitset to store a set of unique integers from a given range (rev. 2)
This is a continuation of this review. I applied most of the proposed changes.
These changes were focused mostly on decoupling the class from the rest of the program and making its interface more like ...
1
vote
1
answer
138
views
Collection that uses a bitset to store a huge set of unique integers from a given range (rev. 1)
Some (skippable) context:
I'm writing program that minimizes an arbitrary logical function. Such function takes an unsigned integer as an argument and returns either ...
9
votes
1
answer
336
views
Construct a performant sieve of Atkin in Rust
I have implemented the sieve of Atkin in Rust. It can find all primes till 1,000,000,000 in 4.5 s using 34.4 MiB on my 1.4 GHz machine. This is a direct implementation (with some optimisations made ...
2
votes
3
answers
309
views
Prevent stack memory usage for recursive function in C
This C code does DBSCAN - Density-based spatial clustering of applications with noise. It's a cluster algorithm for turining unsupervised (no labels) data to become ...
2
votes
3
answers
788
views
Find median value of two Sorted Arrays
To improve my coding knowledge can you please give me suggested changes on my code?
...
3
votes
5
answers
265
views
Comparison of two excel files ignoring line order
Below is a simple method which compares contents of two excel files ignoring the line order.
This method is working as expected.
But, one of my peers in their code review mentioned that initializing ...
0
votes
1
answer
70
views
Aggregate transactions in slips
I wrote code to aggregate transactions in slips. I'm concerned with the performance of my code because it uses 3 loops that are nested so the time complexity will be cubic. This code won't scale well ...
6
votes
1
answer
1k
views
Simple stack allocator in C
My plan is to allocate a fixed amount of static memory at initialization (a few MBs), and use a stack allocator for quick temporary buffers. The idea is to avoid calls to ...
5
votes
2
answers
708
views
Construct mesh from a point cloud
I have been developing a program with C lately, its purpose over the top is to reconstruct meshes from point clouds which are generated by finding the intersection points of numerous rays fired at the ...
3
votes
1
answer
150
views
Doubly-linked list functions
This is my first time implementing a doubly-linked list. I would like some feedback on my code. Any comment would be appreciated regarding the quality of the code, bad implementation, memory ...
1
vote
1
answer
574
views
Comparison of lists of intervals
From the following script, the "similarity" function should be callable to compare two sets of lists and return a certain similarity score. The elements of the lists represent intervals, so [...
1
vote
1
answer
237
views
Large file log parser with less memory footprint
This is a variation of an interesting problem I am currently dealing with. We have a large input file which is being continuously written (size: 10-20G). We need to write a log filter which reads ...
-2
votes
1
answer
134
views
Default food property wording when translation not available
I have food table having number of foods, each food can have specific properties in multiple languages (en, es) like name, description etc. But it is not sure if all of the properties are always ...
2
votes
2
answers
297
views
Generate the number of partitions of each integer
I've coded a program that calculates the number of partitions of n into at least two distinct parts, and is relatively quick too (about N^1.5 complexity). For input 30 000 it takes roughly 4 seconds. ...
7
votes
2
answers
521
views
Solar System simulation with real values in Pygame
Inspired by TechWithTim, I built up the solar system including Pluto. I have added a camera feature, zoom feature and displaying information about the selected planet.
Zoom in and out using arrow keys,...
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 ...
3
votes
1
answer
151
views
Create a forecast matrix from time series samples
I would like to create a matrix of delay from a time series.
For example, given
y = [y_0, y_1, y_2, ..., y_N] and W = 5
I need to create this matrix:
...
3
votes
1
answer
96
views
Python classes which can be used as arrays with any number of bits per index
https://github.com/speedrun-program/small_array/blob/main/small_array.py
As a personal project, I wanted to try to make Snake Game in pygame where the grid can be arbitrarily large. I made these ...
4
votes
3
answers
406
views
Optimize memory and disk usage for sequences of n-bit values
Motivation:
I am working with sequences of n-bit values coming from an ADC. I was initially using a std::vector<unsigned short> to store these values (12 bit ...
6
votes
2
answers
268
views
LeetCode 126: Word Ladder II -- Memory limit exceeded
I am trying to solve LC126, and got a memory limit exceeded for the following solution.
I've seen the answer here -- so I'll try to use Dijkstra as well, but I would like to understand why I get the ...
1
vote
1
answer
363
views
Virtual memory manager in C
Virtual Memory manager that has functions, mappage, unmappage, remappage
If the physical ...
3
votes
1
answer
368
views
Bitmap page allocator in C
Bitmap page allocator that scans the bitmap linearly looking for size amount of pages. Everytime it founds a free page, it check if the next ...
5
votes
3
answers
8k
views
Discussing approaches for converting Enum to String
I need to convert the ENUM to a respective string value for which I came up with two approaches and I'm trying to see why would a second approach be better than the first one if even in terms of ...
1
vote
2
answers
186
views
"Frequency Counter Pattern", Can we get other better algorithm having like, O(n) or O(n log n)
Problem Statement :
Write a function called matchSquare, which accept two arrays (arr1, arr2)
Criteria:
The function should return true, if every value in the arr1, has its corresponding values ...
0
votes
1
answer
267
views
Improving multiple FirstOrDefault statements on same collection
I'm having multiple FirstOrDefault() statements, in this case 2, on a collection.
...
1
vote
1
answer
109
views
An algorithm that minimizes the number of ingredients necessary
I am working on a code that will minimize the number of ingredients necessary to make some dishes.
Each dish can be prepared in an arbitrary large number of ways, with combinations of two ingredients. ...
0
votes
1
answer
82
views
How do I increase the memory efficiency of this longest substring implementation? (C++)
I'm practicing my coding on leetcode.
I implemented the following algorithm to solve the longest substring problem:
...
4
votes
1
answer
366
views
Golang function that reads S3 files and populates maps with strings as keys
I have a below read function which is called by multiple go routines to read s3 files and it populates two concurrent map as ...
4
votes
1
answer
229
views
Minimize memory allocations while calculating the matrix representation of a Hamiltonian
I am writing a script using Julia (calling my functions from the REPL) to compute the matrix representation of certain Hamiltonian. After I run my script I see that the memory allocations count is ...
2
votes
3
answers
187
views
5
votes
1
answer
1k
views
Memory leak I can't identify using Bitmap and Graphics classes
I have some parallel.for one inside another.
the last parallel.for have a normal for that ...
2
votes
3
answers
430
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 ...
7
votes
1
answer
459
views
Find all possible ways a rook can move to a diagonally opposite corner without going back to an already visited square
This question seems similar to this one: Find number of unique paths to reach opposite grid corner but is entirely not. For moving from upper-left corner to lower-right corner we are not restricted to ...
2
votes
1
answer
123
views
iterating a big list of objects throws a memory issue
I'm writing a function which iterate through a list of objects and should return:
true if all the items have the attributes (cp and type).
false if all the items haven't the attributes (cp and type).
...
5
votes
1
answer
255
views
Segmented Sieve of Eratosthenes with wheel factorisation
Problem
I have a project in which I implemented variants of the Sieve of Eratosthenes as well as benchmarking and profiling harnesses for these (which can be ran with ...
3
votes
1
answer
844
views
C# screen recording
I'm developing a screen recording as an application log. The recording should capture a full HD screen at 25fps and on request it should save last 60 seconds of record. It is for embedded app, but the ...