Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
63 views

I disassembled a 7,838,304-Byte portion of /usr/lib/x86_64-linux-gnu/dri/i965_dri.so using Capstone as shown below: #include <stdio.h> #include <string.h> #include <stdint.h> #...
TheAhmad's user avatar
  • 940
1 vote
0 answers
57 views

I mean that i is incremented by 1 right, then how does ptr + i equals ith block of memory since int size is 4? int i, n; printf("Enter the number of Integers: "); scanf("%d&...
0x0pralad0x0's user avatar
Best practices
1 vote
7 replies
170 views

So I'm making a linked list for one of my school assignments in C. I found this website that has some helpful code snippets, and I noticed that they use malloc() to allocate more memory every time ...
Klumpy7's user avatar
  • 123
2 votes
0 answers
88 views

I am trying to learn C, and I want to specifically work with arrays and matrices as I do scientific simulations (coming from python!!). After writing few basic 1-D array codes in C, I am going for ...
Sayantan4796's user avatar
0 votes
0 answers
26 views

I'm learning odin, and I'm writing a program where the map allocating memory, growing and doing its checks is a considerable part of my program running time, is there a way to have a map where I can ...
jhonny's user avatar
  • 858
3 votes
4 answers
150 views

I have a small project (ed-like text editor for myself. Just want to edit some config files using it) and I have some problems with it. workspace_file->flc = malloc(sizeof(char *)); ...
Ho1Ai's user avatar
  • 39
-2 votes
2 answers
136 views

This was a question in a C Programming assignment given to me as a part of last week's assessment. Requesting everyone to kindly explain what needs to be done and how it needs to be done. Kindly note ...
Gargi Chaturvedi's user avatar
1 vote
1 answer
123 views

I'm trying to write a queue that will store strings. Using GDB I can tell that I make a memory allocation error in the function resizeQueue. Here's the exact message: Program received signal SIGTRAP, ...
user31051859's user avatar
0 votes
0 answers
209 views

I have been having issues allocating memory on the GPU with jax. I am running on a cluster that gives me access to a RTX6000 (24GiB vram) which jax is attempting to allocate to. Output of jax....
Kepler7894i's user avatar
1 vote
1 answer
74 views

I am planning to make a Linear Regression model using C. It takes a set of m points as input from stdin using scanf. The points are defined as a struct: typedef struct{ double x; double y; } ...
Nirav Pandey's user avatar
0 votes
0 answers
16 views

Most OpenCL API calls return a status/error value, either directly or via an out-parameter (example: clCreateBuffer()). While that is not as informative as a long-form string description, it can tell ...
einpoklum's user avatar
  • 137k
0 votes
0 answers
103 views

Consider the following excerpt from Prometheus source code: func (ls Labels) String() string { var bytea [1024]byte // On stack to avoid memory allocation while building the output. b := bytes....
vtm11's user avatar
  • 409
11 votes
2 answers
367 views

The following two codes behave as expected: char* test1 = new char[20]{"abc"}; cout << test1; Outputs: abc int size = 20; char* test1 = new char[size]{'a','b','c'}; cout << ...
petat_irrumator's user avatar
1 vote
1 answer
91 views

I have a parent struct that has an array of child structs and the length of it, and within each child struct is an array of numbers and the length of it. all of the arrays are defined using pointers ...
Sterticc's user avatar
-3 votes
1 answer
171 views

I am sorry if the question is stupid. The problem is that memory for my dynamic array inside a static structure is not being allocated. The reason might be my pc (it is a really old notebook with only ...
Safarov Arthur's user avatar
-1 votes
1 answer
141 views

I am trying to solve LeetCode 2487: Remove Nodes From Linked List, and I’ve implemented a solution in C++ that first reverses the list, then removes nodes that have a greater value node to their left (...
notSukuna's user avatar
0 votes
0 answers
19 views

How to setup dynamic allocation for a spark job which is having data rate about 450k? I tried with the below configurations, but the executor pods are always running with the max executors and it's ...
Yashini's user avatar
5 votes
0 answers
124 views

I would like to frequently allocate and reuse buffers of up to multiple hundreds of MBs. I want to use a memory pool for this because I know the target machines possess enough memory capacity and I ...
Clutterhead's user avatar
4 votes
3 answers
175 views

Consider the following code: #include <stdio.h> int main() { int **s = (int**)malloc(3 * sizeof(int*)); for (int i = 0; i < 3; i++) { printf("%d\n", s+i); } ...
M. Saamin Rahman's user avatar
2 votes
0 answers
80 views

I’m developing a custom OS and facing a chicken-and-egg problem with my page frame allocator. I need to map a specific page, but if the corresponding PML4 entry is NULL, I must allocate a PDPT. ...
Viliam Holly's user avatar
0 votes
2 answers
110 views

I have the following code to create one-way list of user-specified number of elements typedef struct Node{ int val; struct * Node next; } Node; int main(){ int num; Node * prev = NULL;...
user98967885655's user avatar
4 votes
2 answers
209 views

I am trying to correctly handle user input in C, particularly when reading a file path from the user. However, I have some concerns: How do I refactor this code to handle dynamic memory allocation. ...
tr41z's user avatar
  • 43
1 vote
1 answer
272 views

The remap function in Zig's memory allocator interface is supposed to "attempt to expand or shrink memory, allowing relocation". In particular, it mentions that... A null return value ...
wildcat's user avatar
  • 81
3 votes
2 answers
153 views

I'm just starting to program in c, so i don't have much experience with manual memory management. Coming from python, syntax like the following is very pleasant: import numpy as np b = np.array([1,2,...
Alberto Méndez -Dettmer Muñoz's user avatar
0 votes
2 answers
131 views

I have wrapped my dynamic memory functions (malloc, calloc, realloc, and free) to track memory usage in my program. I have encountered the following: Calling realloc(NULL, 5) goes directly to my ...
BB_bUrns's user avatar
0 votes
1 answer
87 views

Goal: Enable user to input a huge amount of data (text type) in cmd. I have somewhere in my code a function input_buff(buf, CMD_SIZE); buf is dynamically allocated buffer and CMD_SIZE is fixed to 16. ...
user avatar
0 votes
0 answers
121 views

A simple keyboard extension app showing continuous heap memory allocation each time open the keyboard on screen. For easier understanding see the image below... Here is the KeyboardViewController: ...
Asim Roy's user avatar
  • 10.3k
1 vote
1 answer
68 views

I wrote this code in C where you type a word or sentence (char s[]) and two numbers (l for left and r for right). It's supposed to seperate the string into 3 parts: 1. from start to position l-1 ,2. ...
Mr BaW's user avatar
  • 39
0 votes
2 answers
103 views

I was reading about CPython’s implementation of list.pop(k) method and learned that it takes O(n-k) to remove the kth element of the list since it needs to move the posterior elements one position to ...
Osniel Teixeira's user avatar
0 votes
2 answers
350 views

So we have 2 main memories stack and heap. When I create an simple object of class(A obj) which is heap allocated and if we have data members which require heap allocation and stack allocation then ...
shubham kakade's user avatar
4 votes
2 answers
137 views

I am a beginner, working in VS, in a Microsoft environment, making a To Do List in C. After trying to make the program with the help of Stackoverflow, Chatgpt and a good friend, I manged to do it, ...
Anon26's user avatar
  • 41
0 votes
2 answers
129 views

The following code allocates 256 bytes for a character array and then replaces the space with \0 (similar to what strtok and strsep do). #include <stdlib.h> #include <string.h> int main() ...
9-Pin's user avatar
  • 482
1 vote
1 answer
177 views

Say for example I create a vector with new like this: std::vector<int>* pointer_to_vector = new std::vector<int>{2, 4, 6, -1}; Will pointer_to_vector remain valid (not dangling) for the ...
greenlagoon's user avatar
-2 votes
1 answer
164 views

What is the main difference between using the new operator to create an array with trailing parentheses and without? That is, the difference between the following declarations void* ptr = new int[5]();...
Synex's user avatar
  • 213
1 vote
0 answers
17 views

Somehow in one of or more of my loops are overrunning my buffer but I can't catch it. It's either that or somehow my capacity or size is at 0 when it shouldn't be but either way I can't find the issue ...
Shahab's user avatar
  • 11
-1 votes
1 answer
56 views

i have problems with distributing template. i tried with different syntax, but not a successful way with the error text: error C2512: 'node': no appropriate default constructor available for the code ...
Mohamed Elhaware's user avatar
0 votes
0 answers
35 views

My code failed valgring test.I tried so many times to figure out the error and I gave up.can someone help me to find the error .. // Implements a dictionary's functionality #include <ctype.h> #...
keshika sathsara's user avatar
3 votes
2 answers
146 views

What is the principle of std::string concatenation in C++ ? How does it works in memory allocation ? I found out while exploring a leetcode card that in Java: "concatenation works by first ...
Rimso's user avatar
  • 33
0 votes
1 answer
99 views

#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *link; }; int main(int argc, char *argv[]) { struct node *p; p = NULL; Append(&...
AVINASH BHARTI's user avatar
0 votes
1 answer
235 views

I have a Arduino script running for a few years now. Recently I wanted do some minor updates, but I've been running into problems ever since. Even when I run the older version (the version running ...
Paul Heuts's user avatar
-1 votes
2 answers
135 views

I am a beginner and i am working on a code where the multidim arrays are allocated with the malloc, malloc variant. I have to add an Array with a higher dimension (3D instead of 2D). I discovered a ...
merlin's user avatar
  • 1
1 vote
1 answer
111 views

I am writing code to take in a weighted adjacency list in C. Each edge is stored in the form of a struct. I created an array of pointers where each pointer leads to the list for a node. Here's what I ...
Jennie's user avatar
  • 35
0 votes
0 answers
113 views

https://github.com/Lousifr-Illuminos/IlluminOS/tree/main Little project I'm trying for the sake of learning. It works when attempting to allocate variables sized u8 through u128, as well as creating ...
Lousifr Illuminos's user avatar
3 votes
4 answers
181 views

Say I have a function that allocates some struct (object) and has to allocate additional data when setting its fields. Since each allocation can fail, the object creation may only partly succeed. What ...
user6163780's user avatar
0 votes
0 answers
64 views

I cannot share the actual project code, but I will provide an exact code example for the problem I face. I am trying to implement my own separate component (project) in the solution (Visual Studio ...
YYY's user avatar
  • 1
1 vote
1 answer
135 views

Consider the following minimal working example: program p type t integer,allocatable::i end type type(t),allocatable::o allocate(o) deallocate(o) end This code was ...
V T's user avatar
  • 337
2 votes
0 answers
85 views

I am working on a C project where the goal is to manage memory blocks using dynamic memory allocation function such as realloc and malloc and store their state in a file called block.dat. The main ...
Gr_10's user avatar
  • 71
10 votes
2 answers
1k views

We need to separate allocation and initialization of some heap storage. Unfortunately, client code uses delete p; to delete the pointer. If we had control of the deletion, we could allocate with ::...
Max's user avatar
  • 181
0 votes
1 answer
138 views

I define the square matrix by a 2D dynamic array with the new operator following: int n, i{0}; int value; do { cin >> n; } while ((n <=0) || (n > 20)); int* pMatrix = new int [n*n]; ...
Hà Huy Giáp's user avatar
0 votes
2 answers
159 views

Consider this code: typedef struct my_struct { int a; int b; int c; } my_struct; void some_function(my_struct *value) { // do something } int main(void) { for (;;) { some_function(&...
Cyril's user avatar
  • 3,167

1
2 3 4 5
84