Questions tagged [memory]
The memory tag has no usage guidance.
64
questions
0
votes
0
answers
5
views
How can i allocate memory in the heap without loosing data?
I am writing a text game and my task is to create a function that allocates space in memory for a new game item and returns a reference to it.
The task says that the name and description parameters ...
0
votes
0
answers
19
views
Pset5 speller : whats wrong with "unload" in my program? everything are right except this
the problem is:
**program is free of memory errors. valgrind tests failed; see log for more information.
112 bytes in 2 blocks are still reachable in loss record 1 of 1: (file: dictionary.c, line: 6**...
0
votes
1
answer
41
views
Program is free of memory errors, valgrind tests failed - pset5 speller
I'm am getting this error - program is free of memory errors, valgrind tests failed; see log for more information.
I have tried so many things but I keep getting more errors. Here is my code:
// ...
0
votes
1
answer
40
views
pset5 speller memory errors with valgrind
i've been working in pset5 and cannot make it work. I've read some similar questions and made some improvements to my code, but still can't figure what is wrong. Any tips are welcomed!
Here is my code:...
0
votes
2
answers
58
views
Lab 4 problems when the audio is clearly altered
Source file:
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Number of bytes in .wav header
const int HEADER_SIZE = 44;
int main(int argc, char *argv[])
{
// ...
1
vote
1
answer
19
views
Pointers Memory Allocation
Here I have a user-defined structure "person" that stores two pointers one for the name and one for the phone number.
I create an array people of length 2 of type person.
Each of the ...
0
votes
1
answer
21
views
Filter - Structures & Headers
The problem statement states that BMP files have a particular header with: (1) BITMAPFILEHEADER 14 bytes long and (2) BITMAPINFOHEADER 40 bytes long.
bmp.h (provided) includes the definitions of the ...
0
votes
1
answer
19
views
Pset4 - Memory/reflection problem
So I've been on this reflection in pset4's memory problem for well over an hour and I can't seem to get the first column of height to reflect. Only the first column too, everything else reflects.
here'...
0
votes
1
answer
68
views
PSET4 Blur not passing Check50
My code seems to work (when visually inspecting output files), but Check50 does not pass it. I'm struggling to understand what is causing this issue despite having repeatedly read over the code and ...
1
vote
2
answers
64
views
PSET 5 SPELLER - Passing Valgrind but not Check50
I am very close to solving this, my code is returning 0 errors from Valgrind when I run that on its own, but its not passing the memory errors parameter in check50, so I'm very confused. Any help ...
0
votes
1
answer
22
views
Why is the reference variable for dynamically allocated memory lower on the stack?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int n = 5;
char str1[n];
char *str2;
char str3[] = "World!";
// ...
1
vote
2
answers
332
views
Why Doesn't fwrite overwrite previously copied data?
I'm beginning to wrap my head around the week 4 problem set, and I'm confused about how the fread and fwrite functions work.
As I understand it, fread tells the computer to copy data into RAM, and ...
0
votes
1
answer
23
views
dynamically allocated memory for a node is changed without any dereferencing?
I am in week 5(data structures) and I tried to make a simple binary search tree.
then I tried to create a function for getting around on this tree!
this is a part of get_around function :
printf(&...
0
votes
1
answer
15
views
pointers and addresses
int m=10;
int *ab=&m;
printf("address of *ab:%p\n",&*ab);
printf("adress of ab:%p\n",&ab);
output:
address of *ab:0x7ffd85fddefc
adress of ab:0x7ffd85fddf00
i ...
0
votes
1
answer
168
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
1
answer
35
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
1
answer
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
1
answer
31
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
1
answer
112
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
2
answers
148
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
2
answers
70
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
1
answer
59
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
2
answers
118
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
1
answer
24
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
0
answers
1k
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
2
answers
58
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
1
answer
128
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
1
answer
455
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
1
answer
591
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
1
answer
39
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
1
answer
373
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
2
answers
506
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
1
answer
35
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
1
answer
34
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
1
answer
144
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
1
answer
299
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
1
answer
123
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
1
answer
73
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
1
answer
73
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
1
answer
59
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
1
answer
60
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
2
answers
930
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
2
answers
1k
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
1
answer
3k
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
3
answers
146
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
2
answers
56
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
2
answers
25
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
2
answers
95
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
2
answers
283
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
1
answer
22
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 = ...