27,718 questions
0
votes
1
answer
23
views
Implementing blocking memory management in RTOS [closed]
I am reading about blocking memory allocation idea in book Real time concepts in embedded systems by QingLi.
A blocking memory allocation function can be implemented using both a
counting semaphore ...
1
vote
1
answer
153
views
How to avoid duplicated Compose Multiplatform resources (strings & drawables) across core and feature modules?
I'm working on a Compose Multiplatform project (CMP) with multiple feature modules.
Each feature module contains a composeResources folder with drawable and values (strings,...) inside.
The issue is ...
0
votes
0
answers
57
views
In Kotlin, Is there a way to hold weak reference to a function?
I realized that Kotlin is missing a built-in event mechanism similar to what we have in C#.
So I tried to implement my own and ran into a problem that can easily lead to memory leaks.
My original idea ...
1
vote
1
answer
38
views
Realm Database Operations Causing UI Hangs and Scroll Lag During Extensive Read/Write (iOS 16, SwiftUI)
I have severe UI hang issues whenever my sync worker is running. The app experiences:
Screen navigation freezes
Scroll lag and stuttering
Unresponsive UI during data synchronization
The root cause is ...
0
votes
1
answer
61
views
Why does heavy object cloning degrade JS performance even when using structuredClone compared to manual optimization? [closed]
In a high-performance Node.js service, I noticed that structuredClone() introduces unexpected latency spikes when cloning large nested objects (30–50 KB each). Even switching to manual cloning ...
2
votes
2
answers
99
views
Can you construct a NULL-terminated GPtrArray that doesn't have an element_free_func?
I'm writing some C code where I want to have a NULL-terminated GPtrArray containing static strings. Typically, I would use g_ptr_array_new_null_terminated () to construct a NULL-terminated GPtrArray, ...
Advice
0
votes
2
replies
76
views
What prevents Javascript memory leaks in software applications?
I was thinking back to WinJS or WinUI with Windows Universal Applications (WUA) from about 10 years ago. I am wondering how it compiled and avoided typical architecture errors. If there is no memory ...
0
votes
1
answer
186
views
Identifying a failed null check
I am working on a function that must read one line at a time from a file, give the file descriptor of said file as input.
Here is my get_next_line function, and helper functions on top of it
# include ...
1
vote
0
answers
59
views
Reassigning a Matlab pointer in a loop without a memory leak
We are using Matlab to communicate with a C++ library, and are struggling with memory management.
We create a libpointer pointing to an array, and then try to update its value in a loop. I don't think ...
2
votes
2
answers
88
views
mallopt(M_PERTURB) does not perturb the memory on free
I am trying to catch memory-related bugs such as use-after-free by mallopt(M_PERTURB, <value>).
According to the doc, the memory will be initialized to value when it has been released by free.
...
Advice
3
votes
4
replies
179
views
What happens in memory after return?
public class Test{
static int add (int m, int n){
return m+n;
}
public static void main (String[] args){
int a=1;
int b=2;
int c= add(a,b);
}
}
...
0
votes
1
answer
60
views
Paging in x86: what exactly is divided into pages, and why does the linear address behave differently depending on paging?
I'm trying to fully understand how paging works in the x86 architecture when segmentation is also enabled.
I have a couple of questions:
Does paging divide the logical memory (the selector + offset ...
8
votes
0
answers
182
views
How to safely resize a std::vector and detect allocation failure when exceptions are disabled (ESPHome / embedded C++)
I'm working in an ESPHome / embedded C++ environment, where exceptions are disabled, so std::vector::resize() won't throw std::bad_alloc on allocation failure.
I need to resize a std::vector to match ...
-1
votes
1
answer
64
views
Dictionary memory allocated and buffer pool in mysql
What is the dictionary memory and where does it stores, is it uses the memory of buffer pool or a seperate memory, does buffer pool stores metadata pages also or only user table and indexes, in both ...
24
votes
2
answers
2k
views
Why do JavaScript Websocket objects not get destroyed when they go out of scope?
In JavaScript, when you do something like this,
function connect() {
var ws = new WebSocket(url);
ws.onmessage = function(e) {
window.alert(e.data);
};
}
it will work. But why ...
0
votes
0
answers
87
views
Does the memory allocated by ZwAllocateVirtualMemory share the same context as the user mode process that this memory is associated with
I have a kernel mode driver that calls ZwAllocateVirtualMemory following a call to KeStackAttachProcess all from within a PsRemoveLoadImageNotifyRoutine callback routine.
My question is the memory ...
2
votes
1
answer
127
views
Allocation Squashing by returning ReadOnlySpan over member variables via MemoryMarshal
We have something that looks like this:
abstract class TreeNode {
internal abstract Branches GetChildren();
}
class Leaf : TreeNode {
internal override Branches GetChildren() => ...
0
votes
0
answers
25
views
How to preallocate memory for a map in odin?
I'm learning odin, and I'm writing a program where the map allocating memory, growing and doing its checks is a considerable part of my program running time, is there a way to have a map where I can ...
1
vote
2
answers
198
views
Call Stack - What is stored in the call stack between the declaration of a caller function's last variable and a callee function's first variable?
I am using an Ubuntu 16.04 a 32-bit Virtual Machine OS.
I executed
sysctl -w kernel.randomize_va_space=0
to disable ASLR in root prior to gcc.
I have also compiled this using the command:
gcc -g -fno-...
1
vote
1
answer
100
views
Calculate specific app's memory usage on C# [duplicate]
I’m trying to measure the RAM usage of a specific application using C# (.NET Framework 4.6.2).
I’ve already done some research and managed to get a result using Process.WorkingSet64,
but the value ...
4
votes
2
answers
190
views
Clearing memory in WebApp, after completion
I have a web app written in Delphi 12 using TMS Webcore components.
At logout (which happens by user action, or after idle timeout), I want to clear the memory
for security reasons,
in case there are ...
0
votes
1
answer
50
views
Memory leakage when solving JuMP model in for loop
I have a fairly complex JuMP (HiGHS) model that I have developed for running over "batches" of input data. It runs fine on a single batch, but once I start looping over several instances, ...
0
votes
0
answers
164
views
How to reproduce C++ deleting destructor for a custom allocator?
I am aware that calling delete this in a member function is not UB in itself. In fact, compiler is doing the very same thing when one calls delete ptr, ptr being a pointer to a polymorphic object (...
3
votes
2
answers
135
views
How to generalize a linked list node to store arbitrary data in C?
I’m trying to design a generic linked list in C where each node can store arbitrary data.
Right now I have the following definitions:
typedef struct {
int clientID;
char name[256];
} Client;
...
3
votes
0
answers
155
views
::operator delete in multithreading
I try to understand how ::operator delete sync with other atomic operation. Is any atomic::write --SC-order--> ::operator delete in the same thread?
atomic<void*> A;
T1: old = A.read(relaxed);...
1
vote
1
answer
148
views
Can the compiler elide a const local copy of const& vector parameter?
Consider these two functions:
int foo(std::array<int, 10> const& v) {
auto const w = v;
int s{};
for (int i = 0; i < v.size(); ++i) {
s += (i % 2 == 0 ? v : w)[i];
...
-3
votes
2
answers
183
views
Deleting memory for containers
I have std::map of std::vector of raw pointers.
According to Google AI, in order to clean it I should do:
int main() {
std::map<int, std::vector<MyObject*>> myMap;
// Populate the ...
2
votes
3
answers
267
views
How to detect whether a variable is allocated on the stack or the heap in C?
I’m working on a C project where I need to know if a pointer refers to memory allocated on the stack or the heap.
For example:
int x = 42; // stack variable
int *y = malloc(sizeof(...
-5
votes
2
answers
176
views
How to avoid heap allocation when calling interface methods on multiple struct types in a shared list [closed]
I'm writing a program that is very sensitive to garbage collection so I'm trying to avoid allocating to the heap after initialization.
In the example below, calling Run() will allocate to the heap ...
2
votes
0
answers
87
views
RISC-V bare-metal simulation problem, increasing .rodata array size causes hang during DMA
I am trying to write data starting at a specific address (0x88000000) of the memory (simulated DRAM size is 256 MiB), once all data is written, the DMA unit is programmed using the MMIO registers. The ...
0
votes
0
answers
60
views
Device Free Memory Occupied at the time of large file upload Expo / React Native
Apologies if I didn't perform any checks or standards for my query.
In my app with packages:-
react-native 0.79.5
Expo 53
expo-file-system 18.1.11 and
react-native-blob-util 0.22.2.
I am trying to ...
3
votes
2
answers
180
views
Quickly growing allocated memory by multiple of page size
I need to allocate memory (in C code on a Linux system) in the amount of a multiple of page size, and later increase the allocation (multiple times when necessary) by multiples of page size.
As I ...
2
votes
1
answer
112
views
Why does my custom global allocator crash on large allocations, and how can I handle alignment properly?
I am trying to implement a custom global allocator for use in my Rust application. The goal is to track memory usage and align to 64 bytes. My allocator uses libc::malloc and libc::free for allocation ...
-6
votes
1
answer
170
views
Is it possible to create a buffer a program can read/write to without actually allocating memory on Linux?
I'm using a networking library with an interface like:
read(void *buf, size_t nbytes);
write(void *buf, size_t nbytes);
It enables communication between processes on different machines using these ...
2
votes
1
answer
102
views
Implement a custom runtime memory manager with Emscripten & Wasmtime?
I am using WebAssembly to implement a sandboxed plugin system in a C application. Users can write plugins in any language that will compile to WASM, and we just say "you can import a, b, c ...
1
vote
0
answers
67
views
What is the robust pattern for releasing a shared ByteBuf written to multiple channels, especially with staggered writes and potential failures?
I'm trying to implement a high-performance fan-out (broadcast) service in Netty where I need to write the same, immutable ByteBuf to multiple channels. To avoid memory copies, I'm using ...
1
vote
1
answer
202
views
How do I avoid memory being swapped in Rust?
TLDR: I have a huge array (around 70% of available memory) and I don't want it to be swapped to disk. What's the best way on modern linux to pin a vector in memory so that it doesn't get swapped by ...
0
votes
0
answers
75
views
Scatter File Organization and Compiling
I'd like to preface this with the understanding that I'm not the most knowledgeable on scatter files, but I've been learning a lot in the ARM forums about them.
I'm working with the STM32F429 ...
0
votes
3
answers
219
views
What is the relationship between JMM (Java Memory Model) and JVM (Java Virtual Machine)? [closed]
I often see both terms — JMM (Java Memory Model) and JVM (Java Virtual Machine) — when learning about multithreading and memory management in Java. However, I'm confused about how they relate to each ...
2
votes
1
answer
73
views
Why does memory usage never decrease after large FlatBuffers serialization in Swift (v25.2.10)?
I'm using FlatBuffers in Swift (version 25.2.10) to serialize a large array of objects (1,000,000 items). After serialization, the app's memory usage jumps to about 387 MB and never goes down, even ...
2
votes
2
answers
195
views
Is it safe to .pop_back() from an std::vector in order to avoid pointers/memory shifting?
I have this class:
class Socket
{
[...]
pollfd* fdPtr;
};
And I have a Manager class that creates the actual pollfd objects and adds them to a std::vector named pollFdsVec, to then poll on ...
0
votes
0
answers
206
views
Jax unable to allocate memory despite memory being free?
I have been having issues allocating memory on the GPU with jax. I am running on a cluster that gives me access to a RTX6000 (24GiB vram) which jax is attempting to allocate to.
Output of jax....
2
votes
2
answers
166
views
Base class pointer offset & moving objects
I am designing a memory allocator that is able to move objects during their lifetime. To support this it requires use of IndirectPointer that points to a control block. This control block points to ...
0
votes
0
answers
17
views
Can clEnqueueSVMMap be used with a sub-region of an SVM memory region?
Suppose I've allocated a region of memory with clSVMAlloc(). Looking at the clEnqueueSVMMap() function, we are told that it will "allow the host to update a region of a SVM buffer".
Does ...
2
votes
1
answer
144
views
Using std::move with Constructor(Type t) or Constructor(Type&& t). What's the difference?
I'm studying std::move semantics and I would like this to be clarified to me:
Say I have:
// Message.h
class Message
{
private:
std::array<uint8_t, BUFFER_SIZE> buffer;
std::queue<...
0
votes
1
answer
108
views
virt_to_phys vs dma_map_single in smmu enable system
can someone please help in explaining why virt_to_phys cant be used in case of SMMU to get the IOVA address, as in SMMU enabled system physical address are not exposed , so can we use virt_to_phys in ...
-1
votes
1
answer
103
views
Why is it taking more memory when I access an array directly with iterators instead of just copying the vector
I implemented a function to return the Pascal Tree of numRows rows in 2 ways:
// Making a copy of the last element
class Solution {
public:
vector<vector<int>> generate(int numRows) {
...
1
vote
2
answers
76
views
Why defining string within a function scope allocates it on heap instead of a stack? [duplicate]
According this awesome article there is an interesting case with two given examples:
A:
B:
And there is an explanation for A:
Unfortunately you have not taken into account that such Strings will ...
0
votes
1
answer
46
views
How does a microcontroller keep track of heap free()?
In a microcontroller without any OS, how does the microcontroller keep track of where a malloc will point to in the heap?
char *x;
char *y;
char *z;
x=(char*)malloc(10);
y=(char*)malloc(10);
free(x);
...
0
votes
1
answer
138
views
Make malloc allocate from already allocated buffer
Is it possible to change malloc or new behavior for a somewhat limited scope to actually allocate out of a given buffer that is already allocated? Eg. something like:
char buffer[1024];
void main(...