Skip to main content

All Questions

Filter by
Sorted by
Tagged with
5 votes
1 answer
186 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 ...
ArtyomTop1gg's user avatar
2 votes
1 answer
87 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 ...
digito_evo's user avatar
2 votes
1 answer
52 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 ...
Piotr Siupa's user avatar
4 votes
1 answer
86 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 ...
Piotr Siupa's user avatar
1 vote
1 answer
86 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 ...
Piotr Siupa's user avatar
1 vote
1 answer
203 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 ...
Rohith Uppala's user avatar
2 votes
2 answers
237 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. ...
svok's user avatar
  • 21
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 ...
gavrilikhin.d's user avatar
4 votes
3 answers
342 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 ...
lobis's user avatar
  • 161
6 votes
2 answers
238 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 ...
Mircea's user avatar
  • 322
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 ...
xyf's user avatar
  • 508
0 votes
1 answer
56 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: ...
MrSynAckSter's user avatar
2 votes
3 answers
362 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 ...
Kory's user avatar
  • 31
0 votes
1 answer
65 views

Enter the randomly displayed letter console game

The below code segments compose a simple console game where the user is prompted to enter a randomly generated letter displayed in the console. It also saves and loads user data through a .txt file. ...
mastmartelli's user avatar
2 votes
1 answer
923 views

Alpha beta pruning with memorization (transposition tables) and bitboards (5x5 cumulative tic-tac-toe)

This is my first time trying solve a game using these techniques. I've looked at pseudocode of alpha-beta pruning with transposition tables and rewritten it in c++. ...
Vepir's user avatar
  • 258
2 votes
0 answers
109 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 ...
Šimon Gido's user avatar
3 votes
0 answers
195 views

Memcpy function optimzation

Here is my memcpy algorithm I've been working on: ...
Salmoncatt's user avatar
0 votes
1 answer
73 views

Find a sum using just two different digits

The problem statement was pretty easy and I was able to run half of the test cases, but some of the test cases in the end gave me the error of memory limit reached. What can I do here to improve the ...
Martin's user avatar
  • 13
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. ...
Eduardo Andrés Castillo Perera's user avatar
2 votes
1 answer
125 views

Preserving principle of locality while performing memory allocation

In order to implement an efficient AST visitor preserving the principle of locality, I implemented some reference counting mechanism in C++ with the following set of features: All the newly allocated ...
jackb's user avatar
  • 113
3 votes
0 answers
165 views

Custom allocator for improved cache locality and fast iteration in C++

I am writing a custom allocator for my educational game engine project where I need to iterate through a collection of components(similar to Unity3D) every frame. There are game objects and every game ...
Vignesh Gunasekaran's user avatar
8 votes
2 answers
2k views

hexdump(): A memory layout utility to help debugging / understanding / optimising of C++ memory model

EDIT: Refer this answer for improved solution with incorporated feedback and extended functionality. eg Automatically hexdump both parts of a stack/heap obj like <...
Oliver Schönrock's user avatar
5 votes
1 answer
360 views

Optimizing away log function calls depending on global log level

I am a member of a university team designing a nanosatellite. We decided to implement our own (more lite) logging library to use, instead of, say, Google's glog, <...
xlxs4's user avatar
  • 53
6 votes
2 answers
117 views

Program for activity selection exceeds time limit

I've been trying to solve this problem for some while and the solution I have come up with exceeds the lime limit by 1-3 ms and 2 out of 10 tests get a memory issue error. Why is that? This is the ...
antoniu200's user avatar
1 vote
1 answer
118 views

Python's eval command in Arduino

I have made an equivalent of Python's "eval" command in Arduino (which in itself is quite a feat) but the part that decodes the output of it is not small enough to fit in another 30 functions since ...
PyPylia's user avatar
  • 113
6 votes
1 answer
210 views

Matrix class with space-optimized triangular (lower and upper) variants

I've written a class for square numerical matrices (of doubles, in this case), in C++11. Since I intend to use this class later ...
Anakhand's user avatar
  • 645
7 votes
2 answers
191 views

Prime number segmented sieve

I tried to solve the SPOJ prime number problem below. The code produced correct results, but Time limit exceeded and also memory need around 970M which is not efficient(?) How can I optimize this ...
Devina Muljono's user avatar
1 vote
2 answers
374 views

Codility's BinaryGap: Hardware-aware answer [closed]

This is a well-known question, which some others have posted about on this site. Here's my first shot following a state machine approach: ...
Eduardo J. Sanchez's user avatar
6 votes
1 answer
777 views

Read CSV and use bidirectional BFS to find the shortest connections between actors

I have a really huge file¹ with 17 million records in it. Here is a sample of the file: Actor Movie 1,2 2,2 3,1 4,3 2,3 ...
Akshay Aradhya's user avatar
5 votes
1 answer
261 views

C++ class to compute similarity coefficients

I'm a complete beginner in C++. I wrote a class to compute similarity coefficients using Euclidean distance and Pearson coefficients on map data structure. I would ...
kovac's user avatar
  • 269
7 votes
2 answers
1k views

The performance of the simulation for an ant's random walk on a 5x5 grid

I have written a simulation in order to solve the 280th problem in Project Euler, and the simulation basically repeat the given experiment 5m times, and for each experiment, writes the ExpNo - #...
Our's user avatar
  • 171
1 vote
1 answer
143 views

Implement C++11 multipart sending without copying to a single buffer

I am working on a C++11 project and am migrating the underlying communications library used. The original library allowed sending messages in multiple parts using a ...
Jedi's user avatar
  • 83
3 votes
1 answer
1k views

Counting subsets with sum not exceeding some limit

I am facing a variation of a subset sum problem. I have to count the number of subsets with sum less than or equal to some integer(limit). I think the optimal solution for this problem would be the ...
Y N's user avatar
  • 133
4 votes
3 answers
153 views

Associating a string with a derived class

I am using the following code to get a string that is associated with the class of an instance: ...
oddRaven's user avatar
  • 157
5 votes
1 answer
2k views

C++11 : simple Tree implementation

I have created a C++11 implementation of a simple Tree for an online code challenge, I'd like to know how to improve it and how to make my code use less memory : ...
Stellaris's user avatar
  • 121
0 votes
2 answers
198 views

Calculating shortest possible route between two given nodes

I recently came across this problem: Heroes in Indian movies are capable of superhuman feats. For example, they can jump between buildings, jump onto and from running trains, catch bullets with ...
hellozee's user avatar
  • 389
1 vote
2 answers
2k views

Finding the longest palindrome from the given string

Recently I came across this problem which instructs me to find the longest substring which is a palindrome: As we all know, a palindrome is a word that equals its reverse. Here are some examples ...
hellozee's user avatar
  • 389
3 votes
3 answers
493 views

Calculating number of unharmed leaves

I recently came across this problem that asks you to print the number of leaves not eaten by the caterpillars: As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, ...
hellozee's user avatar
  • 389
1 vote
1 answer
3k views

Brute-force password cracker

I am trying to write a program to find a zip file's password. I know the password consists of only lower-case letters and it's length does not exceed 6 characters. I wanted to check the passwords of ...
FoxyZ's user avatar
  • 13
7 votes
3 answers
9k views

Rotation of elements in an array

We had to write a program that would perform rotation of elements in an array. The array size was entered by user, so it had to be in a sense, dynamic. Rotation or Circular Shifting Initial Array: <...
Max Payne's user avatar
  • 359
4 votes
2 answers
892 views

Memory Management Code

For a project I had to do a memory management problem without creating any custom classes or templates using the provided pool array and ...
Ray McClain's user avatar
4 votes
2 answers
2k views

Binary file validity in C++/C++11: checking a binary header

I have some code for checking a binary header to see if a binary file is meant to be read by a certain program, and I could use some extra eyes to review it. Assume the following ...
Dennis's user avatar
  • 43
0 votes
1 answer
278 views

Simplest linked list in C++?

My context was basically to get my linked list implementation in C++ reviewed, since I wrote it from scratch and wanted to make it as simple as possible and learn from suggestions I get. I am trying ...
ZeZNiQ's user avatar
  • 131
6 votes
2 answers
310 views

Extending Sieve of Eratosthenes beyond a billion - follow-up

Follow up form Extending Sieve of Eratosthenes beyond a billion Taking suggestions from the comments on the previous post: Updated Code: This takes about 22 seconds for MAX as \$10^9\$ to reach "...
piepi's user avatar
  • 823
32 votes
4 answers
3k views

Extending Sieve of Eratosthenes beyond a billion

For MAX value of 1000000000 (\$10^9\$), it takes about 45 seconds to reach the line where it prints "done". How can I speed this ...
piepi's user avatar
  • 823
3 votes
3 answers
3k views

Custom ArrayList class

Please review my custom ArrayList class I constructed from scratch and add any suggestions or constructive criticisms. The point of this template class is give the ...
Jonathan Hernandez's user avatar
6 votes
1 answer
259 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 ...
glampert's user avatar
  • 17.2k