Questions tagged [memory]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
21 views

code is free(): invalid pointer and Aborted, and I don't understand why

at first it worked. But i make style and add more coment and it was broken. It makes all images but in the end: free(): invalid pointer Aborted and i don't understand why. I rewrite code and all work....
0
votes
1answer
24 views

My program is not free of memory errors Speller Pset 5. Can anyone help?

I am working in Speller of PSET5. My program compiles and only has one problem :( program is free of memory errors valgrind tests failed; rerun with --log for more information. The rest of the ...
0
votes
1answer
20 views

i don't know what is wrong when i run the program the output is all zeros

void blur(int height, int width, RGBTRIPLE image[height][width]) { double red_sum ; double green_sum ; double blue_sum ; double counter; RGBTRIPLE new_image[height][width]; ...
0
votes
1answer
30 views

PSET 4 Recover - Copy-Pasting 1 Line from 1 Place to Another Causes Huge Error

This Code Below Worked Fine, I got Passed!! #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <stdint.h> typedef uint8_t BYTE; int main(int argc, char *...
0
votes
1answer
46 views

“File size limit exceeded” in Recover - how does file writing work?

I've been quite frustrated by trying to make progress in Recover. When I run my code, I am unable to make even the first JPEG file as the program continues running until the file size is exceeded. I ...
0
votes
2answers
86 views

Pset5 Memory leak in unload()

I've been working on speller for about two weeks now and I've finally got the programm to work, but valgrind cam up with a few memory errors. I've managed to solve most of them on my own, but the leak ...
0
votes
2answers
39 views

Memory issue (Valgrind “Still reachable”)

My code seems to pass all the Check50 tests except the one for memory as valgrind returns a "still reachable" error. Not sure what needs to be done, any help will be appreciated. Thanks! My Code #...
0
votes
1answer
42 views

Pset5 Valgrind Error: Reachable Memory

I've been on the speller problem for a while and I don't understand where i'm going wrong. Any help would be much appreciated. I'm getting the following error from valgrind when i run it alongside --...
0
votes
2answers
76 views

Speller, pset5. Help fix memory loss. How to fclose properly? How to close char *index = malloc(46)?

I have a problem here, if I fclose(dict_source) (comment where I place it) all code stop working (code stop find misspelled words), also if I try free(index) it's return free(): invalid pointer. Other ...
0
votes
1answer
20 views

valgrind return memory leaking even after free()

This is a code that I have written based on 2013 Section question. I put free at the getAge() function but it is still returning error after running valgrind through it. I really dont know why. Any ...
0
votes
0answers
439 views

“Still reachable” in Valgrind

I have noticed on a few programs that, while none of them have any memory leaks, flag a "still reachable" message when run via valgrind. Does "still reachable" simply mean that there are pointers in ...
0
votes
2answers
35 views

Intuition for what is statically allocated memory vs dynamically allocated memory

So I'm just finishing Lecture 3, and even after research, I can't get a visceral handle on the difference between the two. Yes, I know that one is in stored in the heap, and the other in the stack, ...
0
votes
1answer
115 views

Problem Set 4 Valgrind

I tried to implement Speller, but check 50 returns: :( program is free of memory errors valgrind tests failed; rerun check50 with --log added to end of command for more information. When I run ...
0
votes
1answer
417 views

Speller (pset 4 2019) - Can't fix memory leak in hashtable

I've been working on speller, and all my code does the job fine but I can't get rid of the memory leak valgrind is giving me. It seems to be something to do with my load function. I think it's my ...
0
votes
1answer
430 views

pset5 speller program is free of memory errors

I have search around alot of places and even looked at others code but I dont find my code is that much different. I keep getting program is free of memory errors if I check with cs50. I can run my ...
0
votes
1answer
35 views

Pset5 - Memory leaks - conditional jumps?

My code goes through check50 however it fails due to valgrind test failures. I have looked at the lines the log errors refer to with no avail. What steps should I take to fix this? checking that ...
0
votes
1answer
320 views

Pset5 speller: how can I navigate through the Trie and free the nodes?

so I am stuck on this PSET5 speller for a quite while now, trying different approaches, looking at available information in CS50, shorts, pset problem explanation and I couldn't get to free all the ...
2
votes
2answers
431 views

pset5 speller how to only use 7.4 kb memory?

I found in the Big Board (Spring 2018) that some people only used 7.4 KB memory (as highlighted), while the dictionary contains 140k words. I don't understand how that's possible.
0
votes
1answer
34 views

Errors from context when running trie dictionary from pset5 speller through valgrind

I've managed to implement a trie data structure for speller, and it seems like there are no memory leaks, but when I run valgrind -v ./speller texts/lalaland.txt I get quite a lot of errors from ...
0
votes
1answer
33 views

Pset4 - Array declaration- Heap

In shorts of Pset4 it was mentioned, that pointers are created in heap. Does it mean, that all arrays are stored in heap?
0
votes
1answer
133 views

i don`t know what is wrong with my unload function?

enter code here /** * Implements a dictionary's functionality. */ #include <stdbool.h> #include<cs50.h> #include <strings.h> #include <stdio.h> #include <...
1
vote
1answer
262 views

Pset5 Speller Valgrind error

I got Pset5 Speller to work correctly but I am getting a Valgrind error as follows 568 bytes in 1 blocks are still reachable in loss record 1 of 1: (file: dictionary.c, line: 108) for all the words. ...
1
vote
1answer
121 views

Memory leakage PSET 5

I've successfully implemented the dictionary and it fully works. When I run valgrind I get 2 nodes (224 bytes each) that are leaking. I really don't know how to fix this. Can someone help? ==1316== ...
0
votes
1answer
65 views

pset 4 recover related question

In pset 4 we were suppose to recover images deleted from a camera memory card by means of reading card.raw and writing the jpeg data when a signature was found. Now suppose I want to recover data ...
0
votes
1answer
67 views

Memory address in 64 bit OS

How long is the memory address of a single byte of 8 bytes allocated to pointer variable in a 64bit OS?
0
votes
1answer
56 views

Writing a word puzzle solver and having a problem with freeing heap memory. Would really appreciate some help!

I am having some trouble with heap memory. I am writing some code to solve word puzzles - (from a game called Countdown here in the UK). The game is that you are given 9 letters and the goal is to ...
1
vote
1answer
46 views

GetString() & Dynamic Memory Allocation

I observed in a walkthrough video in Week 4 (structs-0, I believe) David mentions that any variable created with GetString() should be free()d after its usage, due to the fact that, I vaguely quote ...
0
votes
2answers
793 views

(pset5) valgrind - 1 block not freed

I've grinding away at this one problem for a couple of days now, and can't quite work out what's going wrong. My code passes check50. The output is fine. I'm relatively happy with how quickly it runs. ...
2
votes
2answers
949 views

What will realloc() do if the contiguous memory location is already occupied?

Consider- char* name1 = malloc(4 * sizeof(char)); name1 = "Mike"; Now if i want to put "Mike Smith" in the same string "name1", I need 6 more bytes of memory (one for the space and 5 for "Smith". ...
1
vote
1answer
1k views

When we free a dynamically allocated memory, what happens to the pointer pointing at it?

After watching section on "Dynamically allocated memory" (from Week 4) several times, I still have a question unanswered. Consider the following code- // Allocates 4 bytes of memory on heap and ...
0
votes
3answers
124 views

Week 4, Section : Dynamic Memory Allocation

After watching Dynamic Memory allocation section and reading this i am a bit confused, if declaring an array int array[10]; and allocating using malloc int* parray = malloc(10 * sizeof(int));...
0
votes
1answer
42 views

2D array of given size

I want to create a 2D array of ints, where the array's dimension is given at run time (not compile time). So far, I have been using: int **ptr = malloc(m * sizeof(int*)); for (size_t i = 0; i < m;...
0
votes
2answers
20 views

memory allocation observation.

int* x = malloc(10 * sizeof(int)); int y[10]; x[10] = 0; y[0]=1; what is the difference when you allocate memory with this for this two variants. using *x seems to allocate 10 integers using malloc ...
0
votes
2answers
92 views

pset2 Vigenere printf of encrypted string shows 'funny' chars but looping through doesn't. Why?

The first line under // Return when uncommented prints funny chars sometimes ... always when the message to encrypt is one char long. But when looped through as in the block two lines below // ...
0
votes
2answers
237 views

PSET5 - Help with Valgrind? error : “uninitialised value(s)”

I have ran speller in valgrind to see if there was memory leaks and its appears that all memory allocated have been freed. But, I get many errors of type : "Conditional jump or move depends on ...
0
votes
1answer
21 views

How to end with an unsuccesful memory allocation?

when allocating memory, it is recommended to manually check whether the allocation was successful (or more accurately, terminate the program if it wasn't). Main: int main (void) { char *c = ...
3
votes
4answers
5k views

Memory overlap in C

So I am learning C and I have to implement the memset() and memcpy() functions. I've looked them up in linux man pages and I saw that the first takes care of overlapping memory situations but the ...
-1
votes
1answer
91 views

Dose anyone know where memory allocated in resize.c and copy.c? [closed]

I've checked valgrind resize and found out i have a memory leak , 28 byte lost in 3 blocks to be exact , and i don't know where they are allocated , i think in fread and fwrite , but i dont know how ...
0
votes
1answer
23 views

Regarding week4's lecture video

l have just seen the week4's lecture video where it has been cleared out that string is actually char* under the hood! Then, I encountered and example where why he tries to copy a string by assigning ...
2
votes
1answer
1k views

Does only malloc allocated memory on the heap?

Does only malloc() allocate memory on the heap or when we use pointer and normal variables put some value then it will be stored in some memory location on heap. To be clear, below are cases: //...
0
votes
1answer
543 views

Memory allocation when using struct to defined a user defined type

When a user defined type is defined using struct then does it get memory allocation on heap or stack? I am sure that when malloc is used than memory allocation happens on heap but in case of user ...
1
vote
1answer
2k views

how is C memory management different from Java?

I have few below questions related to C program memory and how it is compared to Java memory management: In Java, when JVM process starts, then some memory (defined by Xms and Xmx) is allocated. How ...
5
votes
3answers
223 views

what happens to memory when a variable dies?

Whenever a variable dies, the memory is erased. But is the content of the memory erased? And if so what happens to the contents of the memory ? Why do we see garbage values (that many times does not ...
0
votes
1answer
48 views

Struct array not assigning value being set

I am currently trying to develop a neural network program for pattern recognition. The basis for the neuron are sigmoid neurons, and the network has three layers. At the moment I am trying to develop ...
0
votes
1answer
52 views

Memory allocation when working with files in C

When you fopen a file in C, and you write to it, how is there memory waiting for the additional data? What happens if the file doesn't have free space after it?
0
votes
1answer
382 views

pset 5 valgrind memory leaks

So I am having trouble figuring out how to get rid of this memory leak. The leak is related (I believe) to the const char *'s in the n value of my nodes in the linked list. Here is the valgrind ...
1
vote
1answer
629 views

Memory allocation: recommended practices

I'm rambling a little with hacker 2 (the passwords') and, in the meantime, gained some insight about pointers, mem-alloc, 'valgrind', etc... It's been a truly great, challenging experience. But, ...
1
vote
1answer
66 views

In breakout, why use 12 char to store an int?

Here says: Why did we allocate an array of size 12 for our representation of that int as a string? No worries if the reason’s non-obvious, but give some though as to how wide the most positive (or ...
3
votes
2answers
2k views

Why do macros take more space than an equivalently defined function?

From Programming in C (3rd edition), page 309 Because macros are directly substituted into the program by the preprocessor, they inevitably use more memory space than an equivalently defined ...
0
votes
1answer
1k views

How does valgrind work?

Can anyone explain to me how valgrind works exactly? I mean, how does it know when memory is leaking, allocated and freed?