Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a memory location?

Surprisingly little information turns up by the search engine. The book C++ Concurrency In Action, in chapter 5 states:

In C++, it's all about objects and memory locations.

Then later,

Whatever its type, an object is stored in one or more memory locations. Each such memory location is either an object (or subobject) of a scalar type such as unsigned short or my_class* or a sequence of adjacent bit fields.

The emphasis is as printed in the book, so clearly a fundamental concept, yet there is no definition.

So, what is it? Is it a universal concept or something more narrowly defined in the C++11 standard? How should I think about it in terms of 32- vs 64-bit architecture and the CPU registers? What does it mean that a bit field (or rather, a series of adjacent bit fields of non-zero length) are part of the same memory location? This last statement implies that a memory location can store data of arbitrary length.

If the above quote is the definition, then I am hoping to see a discussion helping to develop intuitive understanding of the concept.

like image 931
user443854 Avatar asked Mar 25 '19 15:03

user443854


1 Answers

It usually doesn't matter what the architecture is because, for a large majority of CPUs in use, addressable locations are in units of bytes.

As @Caramiriel says, the long strip of paper is made out of a series of bytes.

Sometimes you deal with them in larger chunks, say a uint32_t deals with 4 bytes in one go.

When you get to structs or objects, these deal with larger chunks of memory, or multiple chunks of memory so that you don't have to know the details.

However, I think that the C language, and therefore C++, can be ported to a wide variety of architectures where the smallest addressable unit of memory could be larger (or smaller) that one byte.

like image 94
quamrana Avatar answered Oct 08 '22 19:10

quamrana