1,904 questions
1
vote
0
answers
100
views
Golang benchmarks involving goroutines show higher than expected allocations when controlling the timer manually
Using go version go1.25.3 darwin/arm64.
The below implementation is a simplified version of the actual implementation.
type WaitObject struct{ c chan struct{} }
func StartNewTestObject(d time....
2
votes
1
answer
171
views
Does JavaScript object destructuring allocate a new object?
In the following JavaScript, does the object destructuring that follows the creation of target create a new (temporary) object that has to be garbage collected? In other words, are there two objects ...
1
vote
0
answers
59
views
Error with memory while running a small size file
When running the following code:
events <- read.csv("C:\\Users\\jsh274\\OneDrive - University of Canterbury\\6. Data\\3. Scvenja_data\\3. Jeniya\\1. Analysis\\Output\\3.1 ...
-2
votes
1
answer
44
views
If all memory allocated in a daemon will be freed after exit()? [closed]
A simple question that if I do malloc but without free before exit(), the system should free all memory of the daemon automatically, is it correct?
0
votes
1
answer
163
views
What's the Standards-Compliant/Portable way of Creating Uninitialized Stack Memory for C++11 Onwards?
Recently, I came across std::start_lifetime_as, which got me reading about c++ lifetimes in general. This has got me confused about something else, mainly, how to create an array of uninitialized ...
1
vote
0
answers
116
views
In Rust is it possible to have an allocator such that a Vec<Arc<[usize]>> stores the Arcs in contiguous memory
Old Approach
Previously my clause table was much more complicated storing the literals field of the clauses in a Vec which would then be indexed by a Range in a ClauseMetaData structure. But this made ...
4
votes
1
answer
160
views
C++17 Lock-free allocator crashing -- "access violation reading location"
I have a basic block-based allocator that will be used to allocate memory for POD-types in a multi-threaded setting, where all threads will be requesting or releasing memory simultaneously to a shared ...
0
votes
0
answers
77
views
memory allocation using sync.Pool to optimise task retrieval from Redis
I have a service that selects tasks from Redis using a Lua script. I can select up to 1000 tasks at a time. Every 250 milliseconds I will retrieve tasks, and there are several such modules in one ...
1
vote
1
answer
136
views
How to make my julia in-place function wrapper work without allocating new memory?
I am having a specific problem in julia, I cannot seem to figure out. I broke down my code to some minimal working example to demonstrate the problem:
using BenchmarkTools
function f!(u::Vector)
...
0
votes
0
answers
51
views
How make the Optim.jl zero allocated?
Right now I am using Optim.jl to optimise my problem, however, @btime shows the whole script has around hundreds allocations...which is quite a lot. So is there any trick to reduce the allocations to ...
1
vote
2
answers
128
views
C# memory allocation with Memory<T>
I am casually reading about the Memory<T> class in C#, to figure out if I can use it to "format" memory allocations to be more contiguous. I don't know a lot of the finer details of ...
0
votes
4
answers
185
views
Why does malloc initialize the allocated memory to zero? [duplicate]
As far as I know, malloc does not initialize the allocated memory. However, on macOS arm64, all values appear as zero. Why does this phenomenon occur? Is this related to ASLR?
#include <stdio.h>
...
0
votes
1
answer
91
views
Array allocating problem in gfortran "Not enough space"
I try to run the following code on (a 64-bit) gfortran 14.2
program test1
real, allocatable :: a(:), b(:,:)
! allocate( a(3870457856_8) )
allocate( b(8000, 2000000) )
end program test1
and ...
0
votes
1
answer
70
views
Fortran error status for automatic array allocation upon assignment?
For Fortran 2003 (IIUC), the following allocate upon assignment to variable c is legit:
integer, dimension(:), allocatable :: a, b, c
allocate(a(5), stat=istat)
...
allocate(b(4), stat=istat)
...
c = [...
1
vote
1
answer
120
views
Cannot explain alloc/op in benchmark result
I have pretty basic benchmark comparing performance of mutex vs atomic:
const (
numCalls = 1000
)
var (
wg sync.WaitGroup
)
func BenchmarkCounter(b *testing.B) {
var ...
0
votes
0
answers
31
views
How to allocate a pointer of functions that returns a pointer to array of n elements on C++ 20
C++ 20
I have this function:
int (*funcArrayReturn())[6];
The function returns a pointer to an array int[6] (6 elements aggregated).
And I need a pointer of pointers of n elements(in this case 3) ...
0
votes
0
answers
35
views
Prove that object is allocating each time / Prove that object is not cached or singleton
I have loop where I initialize new object. For example
let count = 0;
for(let i = 0; i < 10; i++){
const objectExample = new SomeObject()
}
SomeObject is object from external library.
I don't ...
0
votes
1
answer
76
views
How to access the metadata that malloc stores for each block?
I know that depending of the implementation of malloc, the algorithm used differs (free linked lists, buckets, binary buddy... - and often it is a mix).
So I was wondering if it is possible to know ...
4
votes
1
answer
122
views
Restricted access for allocated arrays belonging to separate object
I was thinking about the utility of non-standard __restrict keyword in C and C++ and how its effect can be emulated by carefully declare (disjoint) value objects .
Restrict is usually explained ...
0
votes
1
answer
98
views
Unable to access dynamically allocated struct char pointer in C
Unfortunately problem looks for me to be quite complex.
I'm having set of structs and function. Pardon me for terrible naming.
hashmap.h
#ifndef HASHMAP_H
#define HASHMAP_H
typedef struct HashMapNode ...
-3
votes
1
answer
126
views
does append empty slice to another slice can process allocation in golang?
i have a small question about 'append' function in golang:
I have a slice1 and a function which calls in for loop and returns some slice2 which can be empty as well. So the question is how golang will ...
1
vote
1
answer
149
views
std::string from const char* with zero allocation
When declaring std::string cpp{}; does this call new/malloc?
Assume we already have a const char* c. Is it possible to move the contents from c to cpp without extra allocations?
0
votes
0
answers
69
views
How to set constraint for optimisation problem to keep to continuity of allocation problem?
I want to allocate 20 districts on a map to 4 institutions. Below are the data I have.
district = {'d1', 'd2', ..., 'd20'}
institution = {'i1', 'i2', 'i3', 'i4'}
distance_in_km = {
'd1': [['i1', ...
0
votes
1
answer
44
views
QST: Why does pandas not provide a method that allocates a DataFrame of a given size?
Just a simple and straightforward question as to why pandas does not provide a method that allocates a DataFrame of a given size (defaults to List[Series[object]], or if schema is given, allocate to ...
0
votes
1
answer
103
views
Jupyter Notebook error: Unable to allocate / Too large work array required, when calculating inverse matrix
I want to calculate the (generalized) inverse of a 30807 x 30807 matrix.
I tried to use np.linalg.pinv(matrix), and the error "MemoryError: Unable to allocate 7.07 GiB for an array with shape (...
2
votes
2
answers
205
views
How to create an uninitialized 2D array?
C# allows you to create an array without it being initialized with GC.AllocateUnitializedArray<T>. T can be any type, such as bool or int. However, I do not know of a way to do this to a 2D ...
1
vote
1
answer
66
views
Why does this allocatable array cause an error?
I don't entirely understand allocation, so this may be a simple problem, but I wrote this Fortran code:
program name
implicit none
integer :: A, B
integer, dimension(:), allocatable :: ARR
...
0
votes
0
answers
43
views
Fortran pointers and allocated arrays, what happens after a "deallocate"? [duplicate]
The following little code compiles and runs w/o error, and gives expected results:
$ cat ptrpractice.F90
program ptrpractice
integer, allocatable, target :: c(:)
integer, pointer :: d(:)
allocate(c(...
-1
votes
1
answer
158
views
allocate as std::byte[10], deallocate as short*
I come to C and C++ from Assembly before 2.5 decades.
I inherited some things implied in assembly, to both C and C++, but later I realized that these things are actually undefined behavior.
One of ...
0
votes
2
answers
273
views
When to use ReadOnlySpan<T> vs explicit / overloaded types [closed]
For the sake of the ensuing question, assume hypothetically that I want to convert a plain-text string into a hexadecimal string; for example, "Hello, World!" into "...
-1
votes
2
answers
314
views
Why is there no time cost to large stack allocations
I tried this quick-bench test and I'm finding that it's the same cost timewise to allocate 200 bytes as it is to allocate 2000000 bytes.
How could that possibly be?
0
votes
1
answer
124
views
Boxing allocation in Composite Formatting
In Rider Resharper suggests to simplify string interpolation.
When doing so, the Heap Allocation Viewer plugin warns me about boxing allocation. And indeed, the IL code is different and when running ...
0
votes
1
answer
206
views
Why is a nested allocator in Rust causing heap corruption?
I've been experimenting with the Rust allocator_api feature and have developed a simple linear allocator. My test cases show this works as expected. However, I want to be able to nest allocators, e.g.:...
3
votes
1
answer
97
views
C++ size of allocated array extraced memory close to returned pointer from malloc
I have lately been experimenting with overloading the new and delete operators, and I noticed something very interesing.
When I allocate, let's say, class T with new T(); vs new T[1](), there is a ...
0
votes
2
answers
124
views
Using if directives in headers
I have a working generic graph. The type for vertex is currently defined as:
typedef struct vertex {
void *data;
char *label;
bool inGraph;
} vertex;
The void pointer can then be customized for ...
0
votes
0
answers
94
views
Is there a chance to use a custom std::pmr::polymorphic_allocator to make std::unordered_map’s buckets implemented as arrays?
While liked-list buckets implementation in std::unordered_map works well when one needs to add/remove elements from the container, it still could be speed up significantly if “stable” or “read-only” ...
0
votes
1
answer
98
views
C++ Dynamic allocation in while(true) [closed]
I'm a beginner in C++, and I don't understand why I can't make this kind of while loop :
#include <iostream>
using namespace std;
const int gridRows = 3;
const int gridColumns = 3;
string **...
1
vote
2
answers
91
views
Reallocation of global variable in C
As I understand, when function is called from translation unit and this function uses global variable of this translation unit, variable address is unchangable. In case of recalling function from this ...
0
votes
0
answers
29
views
How to check for memory overflow in vnl_matrix (VXL) allocation?
I would like to fail gracefully with an error message if vnl_matrix (c++ code) cannot allocate enough memory for initialisation or resizing. Just constructing a large matrix produces a segfault:
#...
0
votes
0
answers
73
views
C++ Collection of different types of static elements
C++ Collection of different types of static elements
Greetings! Unfortunately my C++ is not very good. For an embedded system, I need to implement the task using ONLY STATIC memory allocation.
There ...
1
vote
2
answers
160
views
Are C structs allocated on the heap if they contain a pointer?
In my program I have a method that instantiates a structure and returns it something like this
struct A {
int a;
double * dblPtr;
double ** dblMatrix;
}
struct A initStruct(int a) {
...
0
votes
1
answer
79
views
Output non registering data file in C
I'm not understanding why this code in C doesn't give me an output other than the first printf, and I would like some help. I've already tried swapping the names to input and read the file where I'm ...
1
vote
1
answer
876
views
rust increase the capacity of a vector by n
I'm working on leetcode problem 88 https://leetcode.com/problems/merge-sorted-array/description/?envType=study-plan-v2&envId=top-interview-150 which merges a vector into another vector. Therefore ...
2
votes
1
answer
136
views
Why do allocations occur during broadcasting assignment to a preallocated array?
I am having trouble understanding why allocations are occurring during broadcast assignment, where all operations involved are themselves broadcasted. I am using Julia v1.10.
using BenchmarkTools
...
0
votes
0
answers
47
views
Use of Stack/Heap outside of programming
If I understand correctly, the RAM is virtually divided into stack and heap. Stack takes primitive types/functions etc and Heap deals with the reference types and objects. Stack follows the LIFO ...
0
votes
2
answers
217
views
What's behind the curtain of std::vector range initialization? [duplicate]
#include <utility>
#include <vector>
#include "iostream"
class Person {
public:
std::string name{"no-name"};
Person() {
std::cout << std::string(...
0
votes
0
answers
82
views
Union structs with uint16_t and two uint8_t variables results in 3 byte long allocation?
I have a memory structure that contains various structures and variables defined as below with CRCr as UNION struct that defines uint16_t and two uint8_t variables. Later struct containing bits and ...
0
votes
1
answer
373
views
How to write function in Golang to reverse unicode string with only 1 alloc/op?
I need to write my own reverse.Reverse analog for unicode strings. This is my code:
func Reverse(input string) string {
runes := []rune(input)
var result strings.Builder
result.Grow(len(...
0
votes
0
answers
46
views
Does the same variable allocate the same memory in different languages
I'm checking the bytes of s=a variable allocated in memory using Python.
The result is 50
Will I get the same 50 bytes if I do the same in other languages?
My Python code is here
import sys
s ='a'
...
0
votes
1
answer
140
views
golang strange allocations in slice of pointers
I have simple benchmark to compare performance for creating slice of structs and slice of pointers to that structs
package pointer
import (
"testing"
)
type smallStruct struct {
ID ...