Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Protip: Compute the size before you allocate

Name: Cudder !cXCudderUE 2015-05-02 16:06

I've lost track of how many times I've seen code that uses a dynamically-expanding array when it could've easily calculated the correct size and allocated exactly the right amount. See: string appending, tokenising, just about everything written in JavaScript, etc.

No wonder software is so slow and bloated...

Name: Anonymous 2015-05-03 23:53

>>13
If you kept doing this, you'd be called a retard before long

Many vectorize implementations will double the size every time more space is needed, so the computational cost scales logarithmically rather than linearly as you add elements. This means you may be wasting up to half of every vector, of course, but if you're only allocating a few short ones you won't care.

Name: Anonymous 2015-05-04 1:45

stop smoking, Cudder. exponential growing = amortized O(1)

Name: Anonymous 2015-05-04 1:50

>>18
exponential growing = amortized O(1)
whata fuck man

Name: Anonymous 2015-05-04 1:55

>>19
each time you run out of space double the array in size.

Since it grows 1, 2, 4, 8, 16, 32, 64, ... you very very quickly reach a state where it's big enough and doesn't need to resize.

Name: Anonymous 2015-05-04 2:06

>>20
What if it's bigger than the strict necessity?
Not optimal!

Name: Anonymous 2015-05-04 2:58

>>21
nigger

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List