Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a long pointer?

Tags:

c++

c

pointers

I am reading a book and it mentions certain data type as being long pointer. Just curious about what that meant. Thanks.

like image 454
numerical25 Avatar asked Feb 23 '10 00:02

numerical25


People also ask

What is size of pointer in C?

The size of the character pointer is 8 bytes. Note: This code is executed on a 64-bit processor.

How big is a pointer size?

It depends upon different issues like Operating system, CPU architecture etc. Usually it depends upon the word size of underlying processor for example for a 32 bit computer the pointer size can be 4 bytes for a 64 bit computer the pointer size can be 8 bytes.

How many bytes is a pointer?

Note that all pointers are 8 bytes.

What is a pointer in Python?

Essentially, they are variables that hold the memory address of another variable. For a refresher on pointers, you might consider checking out this overview on C Pointers. In this article, you'll gain a better understanding of Python's object model and learn why pointers in Python don't really exist.


2 Answers

Some processors have two types of pointers, a near pointer and a far pointer. The near pointer is narrower (thus has a limited range) than a far pointer. A far pointer may also be a long pointer.

Some processors offer relative addressing for things nearby. A long pointer may indicate that the item is not close by and relative addressing cannot be used.

In any case, long pointers are a platform specific issue and may not be portable to other OSes or platforms.

Edit: (further explanation and usage of relative addressing)

Address distances are less of a high level concept and more of an assembly language concept. The distance is measured from the program counter (either the current address or the next address) and the start of the object (function or data). If the location is greater than the limit for a small, relative pointer, a longer pointer will be necessary.

Example: Given a system with 32 bit "long" addressing and 8-bit relative addressing. The relative distance would allow for at least 127 bytes in the forward (positive value) or previous (negative) direction. If the target is 1024 bytes away, a full 32-bit pointer must be used.

This is an optimization feature based on the concept that most instructions and data are near by. The majority of loops have a small distance between the start of the loop and end of the loop. These employ relative addressing for execution.

Most data is nearby, whether a data constant or a variable. In more detail, the data is near a frame or reference point. Local variables are placed on the stack, relative to a frame or base address. This base address is the start of the stack before the function is executed. Thus the data can be accessed using addressing relative to the stack frame start.

The processors allow compilers to use specialized instructions for relative (near) addressing. On many processors, the instructions to use relative addressing are smaller than instructions using long address. Thus the processor requires less fetching from the instruction cache and the instruction cache can hold more instructions.

Long and short, near and far, addressing may depend on the scope of the data or function. There are other factors involved, such a PIC (position indepent code), virtual memory and paging.

like image 131
Thomas Matthews Avatar answered Oct 14 '22 08:10

Thomas Matthews


Depending on how old the book is, it might be referring to segmented architectures, where there were two different "sizes" of pointer: near pointers, which pointed into the local segment (and could be fitted into 16 bits), and far or long pointers, which could point into another segment (and therefore were bigger). This is why you see types like LPVOID in the Win32 API: LPVOID is a "long (far) pointer to void", i.e. a pointer to anywhere in memory.

The use of LP and NP is a hangover from Win16 and the segmented processor architectures of the time. In modern Windows, with its flat virtual address spaces, near and far pointers are generally of archaeological interest only: there is only one kind of pointer and you can ignore the "near" and "long/far" qualifiers.

like image 25
itowlson Avatar answered Oct 14 '22 07:10

itowlson