Questions tagged [memory]

Memory refers to the physical devices used to store programs or data on a temporary or permanent basis for use in a computer or other digital electronic device.

Filter by
Sorted by
Tagged with
0
votes
2answers
43 views

Why do some VMs manage their own memory instead of relying fully on the system allocator?

As far as I know, most "serious" VM implementations, such as CPython and the Oracle JVM, do not request new memory from the operating system ("malloc()") each time they create a new object. As far as ...
1
vote
2answers
227 views

Memory Allocation in C++

Does the memory allocated by class pointers get freed by the class destructor once the class method/function goes out of scope? Or do I need to manually free the memory allocated by the pointer (C++). ...
0
votes
2answers
288 views

Can Rust replace the C or C++ programs in the Future? [closed]

I recently read an interesting Article that, due to a memory Overflow error Power system of Boeing will collapse and turns the Flight into a Flying Brick. This is a low level memory Handling bug. ...
-3
votes
3answers
258 views

Is it an ok practice to keep pointers dereferenced?

For me, I prefer having all my variables, not as pointers. Is it ok to keep all heap-allocated variables dereferenced? For example: #include "Foo.hpp" #include "Bar.hpp" class Foo { private: Bar* ...
3
votes
1answer
123 views

Arranging blocks of data for efficient memory access

suppose I have an algorthm that has N blocks of data, and an operation needs to be performed on all blocks such that requires 2 blocks to be in memory at any given time to be done for all possible ...
1
vote
1answer
31 views

What is the difference between a Page Table Entry and a Memory Descriptor List?

The definition of a MDL from Microsoft is: The operating system uses a memory descriptor list (MDL) to describe the physical page layout for a virtual memory buffer. The definition of a Page ...
0
votes
0answers
55 views

Zipping and downloading multiple files

We're currently designing an web application that will basically expose "messages" to end users, each message consisting of a subject and body, but more important 1 to many files we call "attachments"....
1
vote
1answer
157 views

Will Windows handle any memory not freed as well as threads not closed? [closed]

If I had an application that pretty much had a "fail-safe" as in, if I need to terminate the application quickly and not free the malloc'd memory, or close the threads that are running, would Windows ...
1
vote
2answers
253 views

Splitting a critical application into multiple executables

We're developing some C++ application that analyses strings using some data. The data is large (a few gigabytes) and takes a significant amount of time to load into memory, and timing, as well as ...
1
vote
3answers
217 views

Does each process have it's own section of data, text , stack and heap in the memory?

I have created the above picture to illustrate my question. Is there a section within memory (lets say from address 0x1 to 0x15) that all processes use to place their text segment in (left figure), ...
46
votes
3answers
11k views

Why do we still grow the stack backwards?

When compiling C code and looking at assembly, it all has the stack grow backwards like this: _main: pushq %rbp movl $5, -4(%rbp) popq %rbp ret -4(%rbp) - does this mean the ...
2
votes
1answer
348 views

How to optimize reusing a large std::unordered_map as a temporary in a frequently called function?

Simplified question with a working example: I want to reuse a std::unordered_map (let's call it umap) multiple times, similar to the following dummy code (which does not do anything meaningful). How ...
11
votes
2answers
740 views

Why does the base class need to have a virtual destructor here if the derived class allocates no raw dynamic memory?

The following code causes a memory leak: #include <iostream> #include <memory> #include <vector> using namespace std; class base { void virtual initialize_vector() = 0; }; ...
1
vote
3answers
139 views

Is it ok to duplicate a program memory to avoid inline reset?

I have a time-critical function that needs to be executed multiple times sequentially. void task(state_t *state); It uses a relatively large amount of memory, so I figured that allocating it once ...
4
votes
7answers
249 views

Is there a best practice for allocationg/deallocating multiple, dynamic arrays in C?

I was wondering what would be the best approch to allocate/deallocate multiple one-dimensional, dynamic arrays in C. This seems easy at first , however, for me it turned otu to be problematic Considre ...
0
votes
1answer
134 views

Is memory allocation hardware handled or OS?

I am currently working on a bare metal project with an arm processor using GCC arm compiler. If I call malloc, is the allocated memory tracked in the MMU? For some reason I had assumed an OS typically ...
0
votes
2answers
105 views

How did old OSs create or expand a segment in memory without issues?

On an 8086 CPU before the flat memory model had been adopted, when the OS wanted to create a new segment for a process, how did it know what virtual memory ranges were already covered by existing ...
-1
votes
2answers
141 views

Does the OS (kernel) have access to the physical memory

I know that there is a hardware in CPU, the MMU which takes care of mapping a given address to physical address. For example: int *ptr = 0x12345 Will make a pointer to my process address of 0x12345 ...
8
votes
2answers
1k views

Why is DateTime.Month an int?

In C#, the DateTime property Month has a type of int (a 32 bit signed integer) yet its range will only ever be 1-12. What are the reasons the C# team chose int over a smaller numeric type such as byte(...
4
votes
2answers
207 views

Do operating systems implement techniques to ask programs to give up non-vital memory in times of shortages?

When a system is running low on available memory can it ask programs in general to give up any non-vital memory without shutting down. Like a process signal which causes the processes to yield any ...
-3
votes
0answers
70 views

How does an Operating System gets allocated its first memory space [duplicate]

Going through osDev.org, I managed to write a small kernel that outputs a memory address, similar to this: #include <stdio.h> int main() { size_t a = 2; size_t *p = &a; printf("...
-3
votes
2answers
228 views

How are memory addresses created?

#include <stdio.h> int main() { size_t a = 2; size_t *p = &a; printf("%p\n", p); } The above code will print the memory address of a. I understand that within an OS, this ...
1
vote
2answers
2k views

How to process huge amount of data with limited processing ressources? [closed]

I receive daily from an external source a very large amount of data (around 250GB with 260 million rows of fixed width text) distributed over 5 text files. I am writing a Java application that should ...
2
votes
4answers
1k views

Is an Array Index content stored in one memory address?

Assume in C we have the following array of one item: int a[] = {2000}; 2000 in binary would be: 11111010000 If each memory address can hold 1 byte (8 bits) of data, then howcome in some tutorials, ...
107
votes
15answers
14k views

When to optimize for memory vs performance speed for a method?

I recently interviewed at Amazon. During a coding session, the interviewer asked why I declared a variable in a method. I explained my process and he challenged me to solve the same problem with fewer ...
2
votes
1answer
88 views

If you can store BigInts in a more optimal way than an array

This suggests just storing BigInts as an array: // n = -123 var n = { sign: -1, digits: [3, 2, 1] }; However, if you have "big ints", that array will get large: var n = { sign: -1, ...
2
votes
3answers
967 views

How to align on both word size and cache lines in x86

From what it sounds like, a 64 bit processor means aligning to 64 bits, which means if you have unicode utf-8 stored in there, each 8-bit chunk would take up 64 bits of space. That doesn't really make ...
-1
votes
1answer
135 views

Executing an algorithm constantly on slow and fast machine

Is it possible to create an algorithm that will execute at the same rate and speed on faster and slow computers. What i mean is, i have a year 2000 desktop that can run a certain computational ...
5
votes
1answer
2k views

Why do we need to specify the type of data a pointer will hold, if all pointers are the same [duplicate]

Why do we need to specify the type of the data whose address, a pointer will hold, if all pointers are the same. Since all pointers store addresses. Also, the amount of space a pointer will require in ...
0
votes
1answer
126 views

Erlang: Memory implications of passing around large objects in/to functions

Is there a memory penalty to passing around large objects (like an entire http request, or the blob contents of an uploaded file) between functions within the same (Erlang) process? It is my ...
2
votes
2answers
88 views

Linked-list iteration patterns

If you have a linked-list, where the items are not necessarily close to each other in memory, wondering if it is (in general) better/worse/no difference to do the following. Say you want to iterate ...
2
votes
1answer
299 views

Algorithm for efficiently allocating memory

Given the following constraints: No multithreading. No care about hardware cache utilization. Wondering what a reasonably optimal memory allocation scheme would look like. From my limited knowledge,...
0
votes
1answer
49 views

Question about memory handling of trees and certain sorts on large data sets.

If data structures such as trees and certain sorts(quick sort, merge sort) work using recursive algorithms and recursive algorithms take up a lot of memory space in the stack and can only work on a ...
0
votes
2answers
670 views

What is the safest practice in handling QWidget pointer lifespan in a QObject oriented environment?

Consider the following constructor: NetworkTools::NetworkTools(QObject *parent) : QObject(parent) { view = new QWebEngineView(); view->setParent(parent); // Produces an error, shown below. ...
0
votes
2answers
284 views

copying of memory vs pointer to memory in real time systems

While working in a multi-threaded environment, then data sharing seems to be a good option to pass data between threads. While working with real time systems it is apparently advisable to go with ...
1
vote
0answers
178 views

How does the BIOS detect the size of installed memory? [closed]

I'm writing a little toy operating system using a mix of C and Assembly (It's not meant to be good/fast, just meant to learn from). I know that I can issue an interrupt (I think it's INT 0x15) to ...
0
votes
3answers
357 views

Extending the concept of Lazy Loading, to also unloading

A system that sometimes will need to use a pretrained machine learning model. That model is about 10Gb on disk, and when loaded uses about 10Gb of RAM. Loading it from disk takes a nontrivial amount ...
0
votes
3answers
731 views

Memory segmentation - stack, heap, etc.?

So memory segmentation can be done with or without paging. I always hear people talking about stack and heaps when discussing something memory related in C++. However, what I do not get is that if the ...
-5
votes
1answer
87 views

How was memory allocated in Windows 9x compared to Windows 10 ?

I heard rumours that when a new program is executed in Windows 9x, that app had to specify how much memory it needs to allocate beforehand. How is this different in Windows 10 ?
2
votes
1answer
269 views

How do peripherals decide which address to use in memory-mapped I/O?

I've been reading about how memory-mapped I/O actually works and I cannot understand how the system assigns an address or address space to a specific device. Let's say I had two devices that I wanted ...
5
votes
2answers
350 views

Endianess ARM Assembly Confusion

I'm writing code using arm assembly language for college and the I'm really confused about endianess. The default should be little endian but I'm sure the test string has been stored big endian. The ...
-2
votes
1answer
846 views

First Fit Algorithm Memory Allocation

I am currently reviewing memory partitions and I have a problem that is really confusing me. Suppose you have 5 memory partitions: 100K, 500K, 200K, 300K, and 600K. Also suppose you have 4 ...
5
votes
3answers
3k views

What does “address space” means when talking about IO devices?

The following quote is from this page: While some CPU manufacturers implement a single address space in their chips, others decided that peripheral devices are different from memory and, ...
6
votes
1answer
4k views

How does the Base Address Registers (BARs) in a PCI card work?

I am trying to understand how the Base Address Registers (BARs) in a PCI card work, this is how I think they work: Each function in a PCI card have 6 BAR fields, and each BAR field is 32-bit in size. ...
0
votes
1answer
265 views

When is return-value optimization used? [closed]

In the code snippet below, I have a class that holds a vector, and a getter to access it. When I compile my code with optimizations turned on, I would have expected that the call to get_value() would ...
2
votes
1answer
183 views

What does “data bus control” mean?

This video mentions the following: What does it mean for the DMA controller to be granted the data bus control, does that mean the CPU cannot use the bus to access memory and IO devices until the DMA ...
-1
votes
1answer
132 views

Help With Memory Mapped I/O and Hardware Interrupts for Virtual Machine

I've been working on a 24-bit virtual machine to help me learn more about computers and programming in general and was hoping to find a bit more information on memory mapped input/output and hardware ...
1
vote
1answer
184 views

What would be a mathematical rigorous definition of a memory address space?

What is the exact definition of a memory address space? Is it correct to name the set of all the numbers from 0 to the highest addressable byte the definition of an address space? EDIT: I would like ...
3
votes
3answers
897 views

Is O(log n) for memory management considered slow?

I am talking about single thread general purpose memory allocation/deallocation from a global 'heap' as e.g. every C programmer knows in the form of malloc()/free(). I can't recite the actual title ...
-1
votes
1answer
591 views

Why is it possible to access an array out of bounds with negative indexes much further than with positive indexes?

I have written two small programs in which I declare a very small array. Then I try to access values out of bounds. The interesting thing I noticed that when I try to decrement the index I can ...