Skip to main content
Filter by
Sorted by
Tagged with
6 votes
1 answer
241 views

I'm calling a 3rd-party C99 library from modern C++. The API contains a struct that ends with a flexible array member. To allocate the struct on the stack I think I need a byte buffer then cast it to ...
Peter Sutton's user avatar
  • 1,295
1 vote
1 answer
68 views

Consider following Cython code: import cython @cython.final cdef class Fish: cdef double weight cdef class Aquarium: cdef Fish fish cpdef double fish_weight(Fish fish): return fish.weight ...
Přemysl Šťastný's user avatar
1 vote
1 answer
75 views

I have a function re02_match(regexp, use_cache, ...) where I need to handle re2::RE2 objects differently based on whether a cached object should be used (use_cache = true) or a stack-allocated object ...
Henry's user avatar
  • 587
1 vote
1 answer
52 views

I am reading Michael Kerrisk's "Namespaces in operation" series (as I want to implement a container by myself in Linux), and I found myself wondering about something: In one of Michael's ...
Aux Reves's user avatar
1 vote
0 answers
145 views

Lets say I have a large, non-Copy, stack allocated data structure, and then I move it a bunch of times: struct Foo(u8); fn main() { // A big (8MiB) stack allocation let big_stack_data: [Foo; ...
RBF06's user avatar
  • 2,501
0 votes
1 answer
807 views

There is a one line syntax to create an instance and pointer to it, in the heap allocation. Is there one line syntax for the same purpose but with stack allocation? #include <iostream> class ...
Nick's user avatar
  • 11
0 votes
2 answers
88 views

Say for example I have a function that takes some argument and a size_t length to initialize an array on stack inside a function. Considering the following: Strictly the length can only be on the ...
himynameisjm's user avatar
7 votes
1 answer
384 views

I have the following piece of code: extern void func1(char *array); extern void func2(char *array); void myfunction(void) { if (somecondition) { char var2[256]; func2(var2); } ...
Louis Caron's user avatar
  • 1,401
0 votes
0 answers
29 views

I'm a beginner c++ programmer and I would like to know whether it is possible to create stack-allocated objects with a factory design pattern like in this code. ''' class IInterface { public: ...
Pasan's user avatar
  • 1
1 vote
0 answers
145 views

I was reading the JEP doc about Value Objects in Java and came across a line in the motivation section in context of scalarization of objects that read like this: There are optimizations which can ...
Shankha057's user avatar
  • 1,381
0 votes
0 answers
41 views

I have a function that does some reallocating like this: void str_replace(char** str, const char* a, const char* b) { *str = realloc(*str, 100); } and I call that function in main using: char ...
glades's user avatar
  • 5,374
1 vote
2 answers
278 views

I have a codebase with some ubiquitous data structure; and said structure has an std::string member. Now, for reasons, I want this codebase to work when std::string is unavailable, and in fact with no ...
einpoklum's user avatar
  • 137k
-2 votes
1 answer
283 views

I am currently working with vectors and trying to ensure I have what is essentially an array of my vector on the stack. I cannot call Vec::into_boxed_slice since I am dynamically allocating space in ...
Bots Fab's user avatar
  • 199
4 votes
2 answers
291 views

Is it to avoid fragmentation? Or some other reason? A set lifetime for a memory allocation is a pretty useful construct, compared to malloc() which has a manual lifetime.
Olle Härstedt's user avatar
0 votes
1 answer
48 views

class ID { public: ID(const std::string& name) : name_(name) {} // explicit copy constructor as my first solution but gave me same address ID(const ID& other) { name_ =...
cmasterisk's user avatar
1 vote
0 answers
186 views

For a realtime audio signal processing application, we want to make sure that no heap memory allocations are performed from within the realtime threads. As an internal debugging tool used during ...
PluginPenguin's user avatar
0 votes
1 answer
459 views

I would like to solve the massive allocation costs of a c# application. The application itself can be represented by the TickUser class at the bottom, and I'd like to know how to implement the ...
bboyle1234's user avatar
  • 5,017
14 votes
1 answer
560 views

Consider the following example: struct vector { int size() const; bool empty() const; }; bool vector::empty() const { return size() == 0; } The generated assembly code for vector::empty ...
Dr. Gut's user avatar
  • 3,335
5 votes
0 answers
1k views

Are the rules for stack allocation optimization less strict for HotSpot Java 9-13 ? In Java 7 & Java 8 HotSpot stack allocation of objects (due to JVM optimization known as scalar object ...
digital_infinity's user avatar
0 votes
1 answer
90 views

I am working on a bitset implementation. The bitset uses an array of unsigned long long to store the bits. class bitset{ typedef unsigned long long uint64; uint64* bits; ... } Since I ...
elitk19's user avatar
  • 31
-1 votes
1 answer
801 views

I'm trying to have a stack allocated array inside a struct. Well the pointer I mean. But I'd like the allocation to be done without extra code because I know the size when I write the code (I don't ...
Mathieu Van Nevel's user avatar
4 votes
1 answer
347 views

This question is not a duplicate of this one or other similar questions. This question is about clearing a struct after it has been initialized and used already. Update After reading the first few of ...
user23573's user avatar
  • 2,587
0 votes
0 answers
566 views

I am not clear about was static and stack allocation are? Is static allocation static and stack allocation dynamic? Then where does heap allocation belong? How is activation record related to this? I ...
afsara_ben's user avatar
1 vote
1 answer
580 views

I am writing a container that uses alloca internally to allocate data on the stack. Risks of using alloca aside, assume that I must use it for the domain I am in (it's partly a learning exercise ...
OMGtechy's user avatar
  • 8,380
2 votes
1 answer
1k views

I think in most implementations of Common Lisp cons cells are generally/always heap allocated (see Why is consing in Lisp slow?) Common Lisp does provide a facility for returning multiple values from ...
Greg Nisbet's user avatar
  • 7,054
20 votes
1 answer
4k views

Since somewhere around Java 6, the Hotspot JVM can do escape analysis and allocate non-escaping objects on the stack instead of on the garbage collected heap. This results in a speedup of the ...
JanKanis's user avatar
  • 6,812
38 votes
3 answers
3k views

I am porting some C99 code that makes heavy use of variable length arrays (VLA) to C++. I replaced the VLAs (stack allocation) with an array class that allocates memory on the heap. The performance ...
Szabolcs's user avatar
  • 25.8k
3 votes
0 answers
499 views

I'm doing extensive computations in f# on short arrays of uint64; I'd like to stack allocate them to avoid the garbage collector running. In C++, I'd do this: int search(int n, uint64_t* data) { ...
Søren Debois's user avatar
0 votes
3 answers
542 views

There are lots of questions asked about stack & heap on this site. But i want to know about how compiler manages stack actually? Is the stack based allocation is decided at runtime or compile time?...
Destructor's user avatar
  • 14.5k
1 vote
3 answers
209 views

Are there any methods to give the compiler hints that some objects may have a more static behaviour, and allocate things on the stack instead of heap ? For example a string object might have a kind of ...
Catalin Vasile's user avatar
10 votes
7 answers
3k views

In a project about a decade ago, we found that std::vector's dynamic allocations caused a serious performance drain. In this case it was many small vectors allocated, so the quick solution was to ...
sbi's user avatar
  • 225k
30 votes
3 answers
38k views

As my usually used C++ compilers allow variable-length arrays (e.g. arrays depending on runtime size), I wonder if there is something like std::array with variable size? Of course std::vector is of ...
dronus's user avatar
  • 11.4k