All Questions

Tagged with
Filter by
Sorted by
Tagged with
0
votes
0answers
34 views

How to shrink pointers (linked with GSL)?

I have a problem with my code when I was trying to shrink the allocated memory. The result showed : creating matrix reallocating matrix (expanding) defining GSL matrix in new matrix reallocating ...
-3
votes
0answers
65 views

passing raw pointer from C++ to C API [on hold]

I have to interface with C API using C++ objects. The C API has a interface function: int foo(const int* p); At C++ object the function implemented is int fooObj(std::shared_ptr<const int> ...
0
votes
1answer
44 views

memcpy long long int (casting to char*) into char array

I was trying to split a long long into 8 character. Which the first 8 bits represent the first character while the next represent the second...etc. However, I was using two methods. First , I shift ...
0
votes
2answers
32 views

Why does struct memory initalize with random characters? (Embedded)

Using MCUXpresso with NXP MKL02Z16VFM4 for reference. When I declare a struct like so typedef struct { uint8_t DATA :8; } myStruct; myStruct xxx __attribute__ ((section ("xyz"))); the ...
-1
votes
1answer
73 views

Trying to remove the use of malloc - is there an alternative here?

Apologies for the vague title. I am currently refactoring some code written by a previous developer on the team. We are currently using malloc to assign X space in memory to be written to. char* foo ...
-4
votes
0answers
24 views

Value of member of the structure becomes 0 (Member is an array)

I have the following code :- encryption.h file typedef struct { uint16_t encryptionKey[4]; uint32_t untreatedData[2]; uint32_t encryptedData[2]; uint32_t decryptedData[2]; }...
1
vote
1answer
36 views

Memory allocation for vectors of pointers in C

I'm trying to reallocate memory for an pointers vector, originally the vector is: Album* albuns Where Album is a struct; I created a function passing the adress of type albuns and the total number ...
0
votes
0answers
31 views

C stack memory usage breakdown in visual studio

I am developing a memory-critical embedded application in C and currently have the code running in visual studio on windows as easier for debugging. In VS diagnostic tools I see that the total "...
0
votes
0answers
33 views

What is responsible for assigning and linking address for a variable?

When we define a variable (lets talk about C coding in microcontroller), then it is stored in RAM and it has it own address. Then what is responsible for that action of assigning an address for that ...
3
votes
6answers
69 views

If two pointers point to the same memory address, do you only need to use free(ptr) once or twice?

Say we have a struct... struct node{ int data; struct node *next; }; struct node *new_node = malloc(sizeof(node)); struct node *temp_node = new_node; If I use free... free(temp_node); Is ...
0
votes
2answers
100 views

Distance between heap and stack

I'm running a simple program to show the memory capacity between the stack and the heap in the scope of a single process, and am receiving some strange values that I may be misunderstanding. I'm ...
-1
votes
1answer
30 views

why the byte address stores only 2 digits in below example?

int x = 0x76543210; char *c = (char*) &x; Big endian format: ------------------ Byte address | 0x01 | 0x02 | 0x03 | 0x04 | +++++++++++++++++++++++++++++ Byte content | 0x76 | ...
0
votes
1answer
38 views

Thread Safety of Reading a File

So my end goal is to allow multiple threads to read the same file from start to finish. For example, if the file was 200 bytes: Thread A 0-> 200 bytes Thread B 0-> 200 bytes Thread C 0-> ...
1
vote
1answer
42 views

Why the value of a integer variable is changing after reading a string with scanf?

Ley us consider the following piece of code: #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main(){ char again = 'Y'; int code; ...
2
votes
1answer
30 views

Specifying external memory for the Linker

When compiling my code, I get the Data Memory overflow-error, even though all extra variables added since last successful compile, are declared with pointers to external SRAM-memory. I found ...
0
votes
1answer
39 views

C check if space exists in array, if not reallocate more space?

I have to write a program which takes a string argument such as "abcd" and returns a new string like "a-bb-ccc-dddd". so for each char in the string, increment its repetition in new string. In ...
-1
votes
1answer
43 views

How long does it take to access stack memory?

Does re-declaring the same variable over and over again affect the performance of the code? int i,a; for(i=0;i<10;i++) { // Some operations with a } V/S int i; for(i=0;i<10;i++) { int a; // ...
0
votes
2answers
45 views

Problem accessing linked list in C with a printf in a specific function (accessing memory problems)

When I try to compile the code down below the executable does not open. I also tried debugging and I got this error in the printf of viewNode line: Failed to execute MI command: -data-evaluate-...
0
votes
0answers
31 views

Why does printing an array using a pointer to its first element gives reversed array? [duplicate]

As we see in both of the print statements, printing *(x+1) and *(y+1) gives the second element of the array, but accessing the whole 4 byte memory using col pointer prints the elements in reverse ...
0
votes
0answers
31 views

Is there anyway to jump from boot-loader to application in this weird case scenario?

i am using PIC16F18346, nothing wrong, just the thing started to annoy me with some out of hand problem. I have two codes, simply a boot loader and application. they are both inside the PIC memory. ...
1
vote
1answer
34 views

Accessing values stored in bytes in a memory address

Lets say i allocated some memory and have a pointer to it. Int *k = malloc(100); After storing data from a file in this memory address is it possible to retrieve the value at the nth byte? Say for ...
0
votes
2answers
60 views

How can I insert an integer into a block of memory?

Is there any way I can put an integer into a string of known size and if yes how can I read it? For example an (int a=10) into a (char string[200]).
-2
votes
0answers
32 views

Why do I get a runtime error when I delete “int a=200;”? [duplicate]

This runs fine: void main() { int a=200; int *b; *b=1; *(b+1)=2; printf("%d \n",b[1]); } But when I delete int a = 200, I get an error at run time: void main() { int *b; ...
1
vote
1answer
33 views

How to fix this segfault?

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int toggleChars (char* string, char* letters){ int count = 0; char* scurrent = string; ...
0
votes
0answers
85 views

Fibonacci dynamic memory management

I'm currently developing a fibonacci for a project, I've had some trouble when managing memory. During the implementation I execute a iterative structure with for and recursive by rfib function. ...
1
vote
1answer
77 views

How much memory does it take for a structure that contains array of function pointers?

I have a structure written for a hypothetical CPU: struct s { int m; void (*foo[13])(int); char s; }; If address space is 63 bits wide, and if one byte is 21 bits(char is 21 bits), short, int ...
-1
votes
1answer
32 views

Memory Leakage when accessing, using pointer, elements from a struct received by argument

A little of context: I have recently developed a generic function to update a display image based just on which parts of it have changed. For that I receive as parameter a known struct which members ...
8
votes
1answer
71 views

Are object initializations in Java “Foo f = new Foo() ” essentially the same as using malloc for a pointer in C?

I am trying to understand the actual process behind object creations in Java - and I suppose other programming languages. Would it be wrong to assume that object initialization in Java is the same as ...
0
votes
0answers
42 views

Efficient hash function for memory addresses

I want to implement a kind of "smart" malloc, that would keep allocated memory in a data structure so it is easy to free everything in a row. I think the best data structure for that kind of problem ...
0
votes
1answer
33 views

How does modify value on the same memory's address will delete the previous value? “OVERWRITTEN concept on PC's mode operation”

I'm new on world of computing and computers ..I'm developing in C programming and really every time I get stuck in my thinking how really PC delete the old value if we modified it by new value, I mean:...
2
votes
1answer
69 views

Logical memory address for variables in C

Consider the following piece of code: #include <stdio.h> int main() { int a = 10; printf("%d %p\n", a, &a); } If I compile and execute the above code repeatedly, it will print ...
0
votes
0answers
23 views

sbrk(0) isn't always returning the same value

I've been tasked with coding an implementation of the buddy allocation algorithm. I'm not very comfortable with C and my understanding of pointers isn't all that great. I'm trying to code a custom ...
0
votes
2answers
63 views

How to pass variables to a external assembly function

How to pass a variable from a C program to a assembly function. Example: main.c: void main() { unsigned int passthis = 42 extern asm_function(); asm_function(passthis) } main.asm: bits 32 ...
0
votes
4answers
110 views

What is “bit padding” or “padding bits” exactly?

I do not want to molest you with this, but i just can not find anywhere in the internet a well-described explanation for what "bit padding" really is, as well as not in any answer for bit padding-...
0
votes
0answers
18 views

Initializing of variables changes previously declared variable in C [duplicate]

I have the following C code that implements a perceptron neuron. Everything runs fine and the correct weights for the given input (AND gate) are calculated and returned in a struct named model_weights....
1
vote
2answers
57 views

Struct memory allocation issues for message buffer

I'm trying to use static structs as a buffer for incoming messages, in order to avoid checking the buffer on the MCP2515-external unit. An ISR enters the function with a can_message* value 255 to ...
2
votes
1answer
66 views

Segments for variables in C programs?

Where are each expression stored in memory? Where would be constant variables stored? #include<stdio.h> int a = 0; // initialized data segment char arr[10] = "hello"; //...
2
votes
1answer
32 views

Why does memcpy_s zeroize in the case of runtime constraint violation?

In this implementation of memcpy_s (as well as others) the region pointed to by dest is zeroized when a runtime constraint violation occurs. Can anyone explain why is this done? I got footguned by ...
1
vote
4answers
134 views

What is virtual memory? [duplicate]

What is virtual memory and, how it differs from physical memory (RAM)? It says that physical memory is stored on sth on motherboard, while virtual memory is stored on disk. Somewhere it also says ...
6
votes
2answers
75 views

How do pointers assigned to pointers and free() work together?

Why would freeing a pointer say p, which is assigned to where another pointer q points to, free q as well? //for example, int *p = malloc(sizeof(int)); *p = 10; int *q = malloc(sizeof(int)); q = p; ...
6
votes
7answers
306 views

Memory waste? If main() should only return 0 or 1, why is main declared with int and not short int or even char?

For example: #include <stdio.h> int main (void) /* Why int and not short int? - Waste of Memory */ { printf("Hello World!"); return 0; } Why main() is ...
0
votes
2answers
63 views

Accessing a struct given an unknown pointer to a memory address - C

Suppose I am given a (void*) ptr (my basic understanding is, it represents a pointer to a region of unknown data type) passed through the parameter of a function. I am trying to figure out how to ...
1
vote
2answers
54 views

Why did the compiler assign different memory address to the same variable, after re-defining the variable?

The code is as follows: #include <stdio.h> int main() { int i; printf("%p\n",&i); for (i = 0; i < 5; i++) { int i = 10; printf("%d %p\n", i,&i); ...
-1
votes
1answer
46 views

How can a character a and string a stored differently except than a null termination in c?

I came across this line from a book it was written when we store "a" as a string its stored as a character constant followed by null character and a pointer points to it. But when we store a character ...
-1
votes
1answer
27 views

How am I allowed to go “over-memory” in Xcode execution

I've written a function that will allocate more memory that I have available on my machine (16GB), yet it seems running that function doesn't have any affect on my actual machine (the "Memory used" ...
0
votes
2answers
64 views

write hard-codded to RAM at specific physical-address

I want write something in userspace program, for example: write the value 3 in the physical address 0xF7F4900(260MB) from the start address 0x0, while all kernel sits in the range 0-240MB. How can I ...
0
votes
1answer
48 views

How do I make a 25 bit wide unsigned integer alongside a boolean bit?

I was hoping to use bit fields, there's no reason why such a thing would take 5 bytes when I can compress both into 4 bytes, after all, I have 7 bits I don't need in my 25 bit integer, however, avr-...
1
vote
1answer
144 views

Explicit free list (dynamic memory allocation)

I need some help with my assignment. My job is to create/implement malloc/free functions in C using “Explicit free list among only the free blocks” technique. I have already studied a lot of materials,...
0
votes
1answer
28 views

C function for printing the position of an element in an array not working

I am trying to print out the scalar product of two vectors, the value and the position of the max element in each vector, and the value and the position of the min element in each vector. However my ...
0
votes
1answer
35 views

realloc is not reallocating memory [duplicate]

int _add_item( char * _key, void * _value, int item, dict *_dic ){ printf("%lu", sizeof(_dic->key)); printf(" + %lu\n", sizeof(_key)); printf("%lu\n", (sizeof(_dic->key) + sizeof (_key)) )...