[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
What's the point of pointers?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 68
Thread images: 10
File: iavfgkF.jpg (71 KB, 602x622) Image search: [Google]
iavfgkF.jpg
71 KB, 602x622
What's the point of pointers?
>>
so you don't have to copy huge chunks of information and instead just use a pointer
>>
so you can tell where your mouse is on the screen
>>
>>55303158
Reference semantics

Next time please ask >>>/g/sqt/
>>
>>55303158
sometimes i pull on it so hard, i rip the skin
>>
>>55303158
So you can reference something and do stuff with it without caring what it is.

For example, in a game where I want to move to the nearest enemy automatically, all I have to do is set a pointer to the nearest enemy, and my auto-move mechanics will deal with the rest
>>
>>55303186
Well, my daddy taught me a few things too, like uhh.. how to not rip the skin by using someone else his mouth : ^ )
>>
The point is to point
>>
>>55303258
Will you show me?
>>
File: 1467065489073.jpg (8 KB, 261x142) Image search: [Google]
1467065489073.jpg
8 KB, 261x142
Hey anon, where do you live? I want to mail you something.

>Here let me just rebuild an exact replica of my house by yours so you can find it

Uhh, can't I just have the address?

>No. Pointers are useless
>>
To prevent copying data back and forth when you need to change something.
>>
>>55303292
I'd be right happy to!
>>
Yeah, just allocate everything on the stack....

YOU FUCKING FAGGOT
>>
>>55303158
A pointer is an address.
You can use it to point to an arbitrary address in virtual memory.

Imagine if I ordered something from amazon and I built an exact copy of my house next to their warehouse so they could deliver it there.
Then I destroyed the copy after delivery.

Wouldn't it be easier to just give them my address?
>>
>>55303158
Who is this fluid druid?
>>
>>55303158
Dunno what you mean by pointers but sweet mother of ass...
>>
>>55303258
>using the smiley with a carat nose
>>
Why doesn't the compiler take care of this shit? I don't have to worry about pointers/references in Python - I can just use variables Why!
>>
>>55304169
>python compiler
kek
>>
If NULL is the value of a pointless pointer, then dereferencing it is a matter of pointing at non-pointy programmers and laugh at them, at point-blank.
>>
>>55303313
just give >her
your parents address
>>
>>55303619
Anon, do you want Amazon to know your address? No. Obviously, this option is much better.
>>
>>55303158

Question:

do compilers of languages without pointers typically optimize code by assigning pointers to things when it detects it would be an advantage?
>>
>>55304169
Actually, basically most variables in python are pointers since everything is by reference in python. Basically they are just autopointers that do a lot of the memory heavy lifting for you.
>>
>>55303158
One really good example of pointers is in the network stack. Basically the ethernet device has access to RAM through the motherboard so it is able to write packets directly from RAM.

After that, the OS can "move" the data by just passing the pointer around the networking stack, and finally to the application. This allows the consuming application to access the data with no copying and very few CPU cycles.

Obviously, this is very a simplified, but you get the idea.
>>
File: 1429620961272.jpg (48 KB, 658x649) Image search: [Google]
1429620961272.jpg
48 KB, 658x649
>2016
>Not building lists with double pointers
>>
>>55303158
To point.
>>
>>55303158
>What's the point of pointers?

Found the Python "programmer."
>>
>>55303158
Any modern data structure:
Linked lists
Trees
etc

>>55303184
lol
>>
>>55303158
wew... those are very hairy legs
>>
>>55303258
asian spotted
>>
File: referrencing_pointers.jpg (77 KB, 615x831) Image search: [Google]
referrencing_pointers.jpg
77 KB, 615x831
>>55303158
>What's the point of pointers?
This should illustrate the point.
>>
>>55303158
So you don't blow the stack like a cunt
>>
>>55303158
>>>/out/ faggot
>>
>>55306079
Rude!
>>
Duck hunting.
>>
File: java.jpg (26 KB, 499x327) Image search: [Google]
java.jpg
26 KB, 499x327
>>55303158
it like this:
Imagine you and a friend are standing on the side of the highway.
you want them to see what it says on the billboard across the street, so you point to it
because taking a picture, printing it out, scanning it into you computer, running OCR to crate a PDF, converting the PDF to a DOC, copying the text from the DOC, pasting it into an email and clicking send is TOO MUCH FUCKING WORK!!
THIS IS WHAT HAPPENS WHEN YOU PASS BY VALUE YOU STUPID OOP SCRIPTING PIECE OF SHIT!!!
>>
>>55303158

With pointers:

>have some data
>need to manipulate it with a function
>pass the address of the data (pointer) into function
>function manipulates data directly
>done

Without pointers:

>have some data
>need to manipulate function
>make a copy of all the data
>pass the copy of the data into the function
>manipulate copy of data in function
>data is returned by function
>then copy the manipulated data back into where the data originally was
>finally done

With a pointer, the act of passing the data into a function is O(1). Without pointers, it's O(n). Thus, a function call will have no change in overhead based on the size of the data.
>>
>>55303363
>>55307455
/thread
>>
>>55307455
Many languages which do not possess pointers do these abstractions automatically, and don't have much of an overhead. However if you know what you are doing pointers are sweet.
>>
>>55307713
And that's what makes those "many languages" have more bloat, overhead, and become slower than languages that utilize pointers. Even if most modern hardware can handle the overhead, and the speed-loss is minimal, it's still an inefficiency that can be done without. But I'm not trying to get into a debate between Java and C, just stating that there are benefits to each, and downsides to each from different perspectives.
>>
>>55303158
Get out.
>>
>>55303158
>>>/dpt/

STOP REPLYING, THERE ALREADY IS A GENERAL *DEDICATED* TO THESE QUESTIONS
>>
>>55308060
>>55307973
How mad are you?
>>
>>55303158
fucking with memory desu
>>
>not always using a shared pointer
>>
>>55303158
You use your penis to point at things.
>>
>>55307286
>THIS IS WHAT HAPPENS WHEN YOU PASS BY VALUE YOU STUPID OOP SCRIPTING PIECE OF SHIT!!!
Actually, pointers/references are used extensively in OOP, as otherwise it's difficult to modify objects. For example, if you pass a BankAccount object to a function that's supposed to withdraw money from it, one of the things that function will do is call the SetValue() method. But, if you pass the bank account by value, you won't be modifying the value of the original object.

Where pointers are unnecessary is in unstructured spaghetti code, where everything is out in the open in global scope and you modify things directly rather than by passing values to functions.
>>
>>55309405
>tfw fell for the 64 bit penis meme
>>
File: uhhuh.jpg (331 KB, 1440x952) Image search: [Google]
uhhuh.jpg
331 KB, 1440x952
>mfw im grading coursework and see a pointer to a struct smaller than 8 bytes
>>
>>55309695
What's wrong with having a pointer to a small struct?
>>
>>55305737
>he doesn't go on /int/
>>
>>55303516
This anon just means assign variables locally, ergo in a function. Always.
>>
>>55307946
I'm pretty sure the designers for whatever language you are referring to can manage pointers as well as you. Maybe even better than you.

Pointers create a general case, just like lambda functions create a general case.
>>
Besides allowing data aliasing (pass by reference), which is both powerful and incredibly dangerous, the other point of pointers is dynamic allocation. Generally, there are three kinds of memory allocation: static memory contains program code and global variables, the stack contains functions' local variables, and the heap contains everything else.

Static memory and the stack have fixed allocation; the exact location of everything has to be known at all times. This is why, in C, arrays passed to functions have to either be pointers or they have to have fixed width (so they have known size). The heap allows you to allocate any amount of memory, and you don't have to know ahead of time how much you need. In C, you get heap memory with the malloc function; in object-oriented languages, you get heap memory with the new keyword.

Since the heap is a pretty random mish-mash of one-shot allocations, you need to keep track of what you've allocated, which is (mostly) what pointers are. Likewise, in an object-oriented language, the handle that refers to an object is a pointer, which was clearer in C++ where you actually use pointer syntax. (And also in C++, stack allocation of objects was possible in some circumstances.)
>>
>>55309695
that is a profound pic. somehow in all my time on /pol/ I have never seen it. It really demonstrates who Hitler was: focused, determined, vigorous, and surely simple minded. but it also displays who he was surrounding himself with: military men; educated men; dull men; men who craved power and men who were sure they knew what was best.

thank for sharing this anon, on this moment of viewing I am euphoric.
>>
>>55311306
>somehow in all my time on /pol/ I have never seen it.

that's just so unbelievable since /pol is so consistently filled with the most brilliant and far-reaching minds civilization will ever know
>>
>>55311382
it's very easy for outsiders to proclaim mental illness upon another when they can't experience the glory and splendor that the greatest and most brilliant minds are capable of achieving.
>>
is a pointer just used like a variable but it could be anything not just a set type?
>>
File: 1424183010967.jpg (75 KB, 548x720) Image search: [Google]
1424183010967.jpg
75 KB, 548x720
what's the point of anything?
>>
File: neat_phone_case.png (2 MB, 1254x1416) Image search: [Google]
neat_phone_case.png
2 MB, 1254x1416
>>55312016
Ass
>>
>>55312016
Agreed. When do you plan on killing yourself?
>>
>>55312016
when I was about 13 i got in an argument with my childhood friend (who i've long since fallen out of contact with). he told me i've never had a gf and kissed a girl. i lied and said i had. that was 10 years ago and i still haven't. thanks for reminding me.
>>
File: 1406749372692.png (227 KB, 500x364) Image search: [Google]
1406749372692.png
227 KB, 500x364
>>55303158
>Whats the point of indirect addressing modes
>>
File: null_pointer.webm (2 MB, 1280x720) Image search: [Google]
null_pointer.webm
2 MB, 1280x720
>>55303158
To confuse people and make things more efficient.

/g/ still can't have audio webms? This will have to do then.
>>
>>55303158
I'd point my dick right to that booty
>>
>>55309891
the pointer ends up being bigger than the data?
>>
>>55315741
>>Whats the point of indexed indirect addressing modes
Fixed.
Thread replies: 68
Thread images: 10

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.