95 questions
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
vote
1
answer
110
views
Is there a way to create a static array in the .data section, where its length is calculated by the size of the .bss section on the Arduino?
I'm just wondering if there is a way I can tell the compiler that I want to create a static array inside the .data section of the Arduino's SRAM, where the array's size is calculated using the size of ...
0
votes
2
answers
94
views
Jagged Array in C without Dynamic Memory Allocation
Task: Implement a function in standard C that constructs a jagged array J from a linear array W. You must adhere to the following specifications and constraints:
Input: The function takes a ...
1
vote
1
answer
105
views
Malloc memory assigned pointer living on a static variable is auto freed or its really a leak?
Consider this case:
Using macos leaks -atExit -- have this code:
#include <stdlib.h>
int main(void)
{
char *leak = malloc(100);
return (0);
}
that is naturally a leak...which "...
0
votes
1
answer
217
views
Changing from dynamic memory to static memory
I'm trying to change a dynamic memory object to static memory use to hopefully free up memory in a way.
Original code(dynamic):
Class.h:
Class() {
auto output = std::unique_ptr<uint8_t[]>(new ...
1
vote
1
answer
75
views
Why are there empty spaces among stack memory allocated in C? [duplicate]
cf. Environment: Microsoft Visual Studio 2022 17.5
// main.c
int main() {
int a = 0x12345, b = 0x67890;
int arr[5] = { 0x1234, 0x2345, 0x3456, 0x4567, 0x5678 };
return 0;
}
If I execute ...
0
votes
1
answer
141
views
C++ Compiling Static Arrays of Unknown Type
Here is my code:
template<typename T, std::size_t N>
class my_array {
public:
const T& at(std::size_t index) const
{
if(index>N) throw std::...
1
vote
1
answer
115
views
Why does calling a function in a different order cause a segmentation fault in C?
I am working on a program in C that processes an array of character pointers. I have several functions that operate on this array, including longest_name(), unique(), and others. When I call the ...
0
votes
1
answer
563
views
How can I declare a zero initialized vector in Assembly AT&T in the .bss section? [duplicate]
I would like to declare a vector in the .bss segment, but I am not sure how to do so.
I would like the vector to have 30000 bytes.
I have tried to compile some C code into assembly, but I don't quite ...
-2
votes
3
answers
987
views
How rust store Strings in arrays? [closed]
As i know from c/c++ and general knowledge of data structures, arrays are structured as sequential memory blocks with constant size. So if I create an array of five i32 variables then array size bill ...
-1
votes
2
answers
119
views
How is static array expanding itself? [duplicate]
I wrote a code for entering element and displaying the array at the same time. The code works but since char A[4] is static memory why does not it terminate/throw error after entering more than four ...
-2
votes
2
answers
773
views
C programming pointer, bytes and memory allocation have 8 question
I am trying to get the bytes and pointers and how they are stored can any one explain or answer some of my questions. Thank you
int num = 513; <-- allocating a 4 bit memory by initializing
//[01][...
1
vote
1
answer
74
views
Why accessing variable declared locally from outside is working?
In tree, while taking input (inside takeInput function), tree node was made using dynamic allocation, but I tried doing it statically, but as tree node were declared inside a function locally it ...
0
votes
0
answers
50
views
What are differences between static and dynamic declaration of array [duplicate]
I am new to C++ programing, I learnt that all the static variables are allocated at compile time on stack memory, so their size should be known before compiling by the compiler.
But the dynamic ...
-1
votes
1
answer
233
views
Detecting pointer target: static memory or dynamic memory?
Is there functionality, in C++, to detect whether the target of a pointer has been allocated from dynamic memory or is living in static memory (including global memory)?
In the example below, I'd like ...
-1
votes
1
answer
146
views
Dynamic memory allocation causing SIGSEGV (Signal: segmentation violation), In attempt to work with malloc and free
I am creating a mathematical data structure in c++20 (Mingw-w64 clion) which i can partially offload from memory to storage and vice versa, Due to its capacity and size. While learning how i could ...
0
votes
1
answer
3k
views
How to create a linked list without dynamic memory allocation as template in c++
I started working through the book Hands-On System Programming in C++
and I tried to create the following linked list with a template without dynamic memory allocation. But every time I try to build ...
3
votes
1
answer
181
views
Learn C the Hard Way's ex17 database design issues
I'm really stuck on this one. ex17 is supposed to be teaching me heap and stack memory allocation by providing a simple database (my questions are specific, but i'll leave it there just in case you ...
1
vote
1
answer
857
views
Difference between using malloc and char array[i] when using strorage in functions
What is the difference between defining an array of a length that is definied before runtime (depends on command line arguments) with array[size] and using malloc()? array[i] leads to the data put on ...
1
vote
1
answer
2k
views
return byte array with Arduino
I have an array that contains bytes of information (a payload), but I want to use this array in two functions. How can I return it? I don't know if I have to declare it different or in other place.
...
0
votes
1
answer
649
views
Why use custom dynamic memory allocation over memory from stack?
Context: I'm working on a project where a client needs us to use custom dynamic memory allocation instead of allocating objects from the stack. Note that the objects in question have size known during ...
2
votes
1
answer
676
views
Is Static Dynamic Memory automatically free'd at the end of a Program?
The static keyword keeps the pointer alive until the program terminates, but is the memory allocated to the pointer buffer free'd automatically when the process terminates? or does the programmer have ...
1
vote
1
answer
606
views
Using waveOutWrite with Dynamically Allocated Memory
I have been experimenting with sound using C.
I have found a piece of code that would allow me to generate PCM wave sound and output it through the sound card.
It worked pretty well for what it was.
...
0
votes
0
answers
80
views
statically allocated variables given memory at runtime
This problem has been bugging me for quite a while now.
int n;
cin>>n;
if(n is even) {
char c;
cout<<"character created";
}
else {
double d;
cout<<"double created";
}
now if the ...
1
vote
1
answer
390
views
Do I need virtual destructors in a world without dynamic memory?
Virtual destructors are needed when an object is (potentially) destructed from a base class pointer.
Consider a program without dynamic memory as often found in embedded systems. Here, using new or ...