Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-3
votes
0answers
55 views

The time and space required for an algorithm [duplicate]

I am trying to understand the concept of time and space required for an algorithm, asymptotic notations and so on. I have couple of questions: 1) Does the space that an algorithm uses in the memory, ...
4
votes
7answers
223 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
69 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
94 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
107 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
882 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
200 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
65 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
184 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
293 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
338 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, ...
106
votes
14answers
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
79 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
228 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
125 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 ...
3
votes
1answer
322 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
107 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 ...
1
vote
1answer
48 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
207 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
48 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
328 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
221 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
166 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
281 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
554 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 ...
-4
votes
1answer
78 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
173 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 ...
4
votes
2answers
212 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
676 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 ...
4
votes
3answers
1k 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, ...
4
votes
1answer
2k 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
187 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
145 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
115 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
179 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
809 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 ...
-2
votes
1answer
357 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 ...
26
votes
3answers
6k views

Why does a long int take 12 bytes on some machines?

I noticed something strange after compiling this code on my machine: #include <stdio.h> int main() { printf("Hello, World!\n"); int a,b,c,d; int e,f,g; long int h; ...
1
vote
1answer
118 views

What architectures have “weak” memory models?

I'm a long-time Java programmer familiar with the Java Memory Model. I'm starting to learn C#, and based on what I've learned so far, the C# memory model seems to be very similar to the JMM. This ...
-4
votes
1answer
116 views

Memory bit address

I am having trouble to understand the following question for my Computer Architecture assignment. Consider a system that has a direct-mapped cache that contains a total of one megabyte; each line ...
5
votes
0answers
737 views

Best Practices For Writing Memory Efficient CSS

What are some best practices for writing memory-efficient (for the lowest peak memory usage) CSS? I realize this is a broad question, so I have broken it down into two main categories: What are 'do's ...
3
votes
1answer
222 views

How can I efficiently implement batch allocation in a freelist?

I've been implementing Andrei Alexandrescu's allocators as an exercise, but I've gotten stuck on his Freelist. Andrei's Freelist looks something like this: template<class BaseAllocator, std::...
-5
votes
1answer
327 views

How to convert a logical address to a paging system

ive had a look around and I cant seem to find an answer or how to work out this question, its a tutorial question for my operating systems course and ive looked through the notes that come with the ...
3
votes
0answers
129 views

C#: simulate PostScript memory allocation

I'm working on a PostScript interpreter in C#. PostScript has memory management. It has virtual memory (VM). It also has objects. Two types of objects: simple and composite objects. Composite ...
3
votes
2answers
196 views

Protecting Structure from corruption

I am developing a safety critical embedded system and I am programming in C. We have a set of const structure declared in memory and they hold some critical data. I want to make sure that any of ...
6
votes
8answers
1k views

Strategies for implementing memory leak detection [closed]

What strategy would you use to detect memory leaks? I was asked this question in an interview that was mostly focused on C++, and couldn't find an answer. I said that there are tools that do it and ...
3
votes
1answer
302 views

Is global state evil if it doesn't change behavior?

I have a library in C where the API uses "objects" to interact with the application. These "objects" are opaque pointers that are created, destroyed, and modified via API calls. These "objects" do ...
3
votes
2answers
855 views

Insertion sort vs Merge sort - memory access

I am a computer science sophomore doing a data structures and algorithms course. My professor said that insertion sort requires random access, while merge sort does not. According to him, the ...
3
votes
1answer
1k views

Purpose of Segmentation and Logical Addresses in 8086

In 8086, mapping of logical adderss to physical address is done with the help of segmentation. Segment registers : offset, and you get the physical location in a 2^20 byte RAM, even though you have 16 ...
20
votes
3answers
5k views

Professional way to produce a large problem without filling up huge arrays: C++, free memory from part of an array

I'm developing a physics simulation, and as I'm rather new to programming, I keep running into problems when producing large programs (memory issues mainly). I know about dynamic memory allocation and ...