[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


a3f278 No.1624

Currently learning Sepples, and I'm genuinely curious about how pointers are used in a general basis. What are some situations where pointers would make your life easier, or save your ass or time? So far, I've only seen how useful it can be for iterating through shit like arrays and cstrings…

ba4b36 No.1626

>>1624
For building abstract data structures.
Also, for when passing the data is too expensive, but you really need to use a profiler and a CPU cache simulator in that case to make sure it's worth it.

5c95be No.1631

>>1626
OP here, I think I see what you mean, if I was working with or targeting a potato or working with embedded shit controlling everything 'by hand' would be that tiny bit more efficient… That's pretty cool, actually.

4255ff No.1637

>>1631
> if I was working with or targeting a potato or working with embedded shit controlling

Actually, I thought of modern full scale computers, where memory access is expensive.

3bb39d No.1668

File: 1426236143881.jpg (271.8 KB, 1024x768, 4:3, richardo.jpg)

>>1631
> if I was working with or targeting a potato or working with embedded shit

You disgust me,i bet you think tech startups are the coolest thing you fucking yuppie.

a3f278 No.1673

>>1637
Oh I see, I guess I misunderstood what you were saying. Excuse my ignorance, I'm still reading babbys first c++ books.
>>1668
y-you too

ab8e0d No.1691

File: 1426377606208.png (66.48 KB, 625x626, 625:626, bait.png)


29652d No.1724

>>1624
Linked list
You have a pointer to the next element

0bce2f No.1747

Anything that requires indirection. That recursive data type? You're going to use pointers. Want to modify this stack allocated variable in this function? You're going to use pointers internally.

c4abfd No.1768

How about a linked list?
Function pointers, maybe?
Flyweights?
Basically everywhere that a "reference type" in managed languages are useful, plus some more.

b33ed6 No.1992

It's like references that you have in your everyday language, but on steroids.

df33de No.1998

>>1626
Since we're talking about data structures, how about structs? Can I be sure that the order of the elements in memory reflect how they are arranged in code? Could I malloc a variety of structs of varying sizes, but keep a common type on top (say, a char*) and then use that as a header?

b8145a No.2000

>>1998
I think so, yes. That is what gobject uses

802746 No.2002

>>1998
Padding bytes will be added to keep everything in 4 byte chunks but reordering isn't allowed.

https://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86

b768ae No.2044

Deletions in Linked Lists and Trees are a lot prettier if you can read pointer.

4d7663 No.2098

>>1624
Most common use is a more convenient way to generate SIGSEGV than kill(2)

a36148 No.2401

>>2098

int die() { return *(int *)0; }




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]