27,717 questions
0
votes
1
answer
30
views
Why does heavy object cloning degrade JS performance even when using structuredClone compared to manual optimization?
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
74
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, ...
-1
votes
0
answers
19
views
Kubernetes memory of pod over time [closed]
I'm having a pod which is eventually reaching thrashing, I'm running 200 golang binary (main.bin) in a pod of 128 MiB because of a resource issue. Ofc, I can increase the memory for it to not ...
1
vote
0
answers
56
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 ...
Advice
3
votes
4
replies
174
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);
}
}
...
8
votes
0
answers
172
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 ...
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 ...
2
votes
1
answer
125
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() => ...
1
vote
2
answers
193
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-...
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
0
answers
163
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
0
answers
152
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);...
-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 ...
-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 ...
0
votes
0
answers
56
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 ...
2
votes
1
answer
110
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 ...
2
votes
1
answer
97
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
1
answer
192
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
3
answers
211
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
2
answers
194
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 ...
2
votes
2
answers
160
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 ...
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<...
-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) {
...
0
votes
1
answer
45
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);
...
2
votes
0
answers
67
views
How can I dynamically trace and visualize memory allocation patterns of nested Python coroutines in real-time?
I'm trying to understand how memory is used in my async Python application. I have multiple coroutines running, and I want to see how much memory each one is using, especially when they are nested or ...