#How to create array with size 1000000???

45 messages · Page 1 of 1 (latest)

rough relicBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

fluid hill
#

i can use vector if it will work

hollow wave
#

An array of what?

#

Making an array that large on the stack will almost certainly segfault yes, the stack is small

#

Either put it in static storage (global) or put it on the heap, vectors are a good idea

fluid hill
#

would vector with this big size work?

fluid hill
hollow wave
fluid hill
#

ok

#

bruh

#

memmove is not working the same for

#

vectors

#

memmove(parts + 1, parts, p * sizeof(parts[0])); //shift right by 1 snake parts pos

#

how to make it work for vector?

hollow wave
#

Don't memmove vector contents

#

User vector.insert

fluid hill
#

ok

#

thx

#

!solved

rough relicBOT
#

Thank you and let us know if you have any more questions!

fluid hill
hollow wave
#

Well yeah

#

If you’re repeatedly shifting over a million items lol

fluid hill
#

bruh

#

i need to make it faster

#

its very important

fluid hill
hollow wave
#

@fluid hill rethink your approach, why do you need to insert stuff at the beginning

cosmic valley
#

Use a linked list?

fluid hill
fluid hill
#

is linked list faster?

opal plinth
#

insertion in a linked list is faster

#

that's the only reason why you'd ever want to use std::set cppthonk

hollow wave
cosmic valley
languid vault
#

but yeah, in general data this big isn't ideal

hollow wave
#

Linked lists are almost always slower than alternatives

#

But if you really must insert at the beginning of a list of a million items it may very well be faster

fluid hill
glossy maple
#

Preallocate a huge buffer at the beginning of your program and use it

#

Did you consider other stuff might be eating up your cpu time

fluid hill
#

Luke Stackwalker shows