Pregunta técnica de Arrays Dinámicos y Arrays Státicos.

Previous topic - Next topic

mentalthink

Hola Compañeros queria formular está pregunta, ya que como sabéis no tengo demasiadas nociones de programación, y tengo está duda que seguro que más de uno de los que andáis por aquí sabréis de seguro la respuesta.

Bien entro un poco en materia para que os hagáis una ligera idea:

En mi juego (de naves), tengo el disparo del Player , el cual hago con un array Dinámico, o sea pulso y agrando ese array, pero me surge una duda para el tema de optimizar... Sería preferible hacer un array fijo con el número máximo de los índices de ese array, por ejemplo si tengo máximo 200 disparos, es mejor declarar el array desde un principio como shot[201]...

La pregunta me surge, ya que (estó es suposición mia, como digo no se demasiado sobre intringulis técnicos), si tengo el array Dinámico, cuando voy agrandando ese array, lo que hay debajo de la pila lo tengo que mover hacia abajo, entonces supongo que todo ese proceso conlleva un "desgaste" para la CPU, en cambio si lo dejo fijo, tendré a veces 180 o 50 o x posiciones libres, pero no tendré que mover para nada el Stack , y por lo tanto esa faena de mover quizás un gran  número de posiciones de memoria no tendrán que ser modificadas por la CPU...

Supongo que si lo que digo tiene algo de sentido, se podría solucionar poniendo ese array dinámico, casi al final de la pila de la memoria del cacharro, pero supongo que se deberia hacer con punteros, y eso ya es otro mundo... al menos para mi...

Gracias de antemano, y si no me he expresado bien, y necesitáis un gráfico, lo hago sin problemas, ya que es algo que me procupa bastante con el tema del rendimiento , más que nada en los móbiles...


Slydog

Sorry for responding in English.
Your translation didn't come out too well, so I'm not 100% sure what you are asking / saying.

But what I did read gave me an idea for a new feature request.
An array that is dynamic, but where you pre-allocate a specific maximum size when declaring the array.

That way you can use the convenience of dynamic arrays without worrying about GLBasic having to reallocate memory each time, which may slow things down.

Code (glbasic) Select

GLOBAL bullets[] AS TBullet
DIM bullets[0], 100 // Clear the 'bullet' array, and allocate upto 100 bullets for the future  [New Feature]
LOCAL bullet AS TBullet
LOCAL bx%
// Add 100 new bullets to the array
FOR bx = 0 TO 99
DIMPUSH bullets[], bullet
NEXT
// Add one more to the already full array
DIMPUSH bullets[], bullet  // Error, ie. array full, or out of bounds (or allocate 10 more, see below optional feature)
DIMDEL bullets[], -1 // Remove last bullet, index 99
DIMPUSH bullets[], bullet  // No error this time, puts into index 99


Actually, it would be better to have another option that when the array gets to the max size, have it allocate an additional number of items.
Code (glbasic) Select
DIM bullets[0], 100, 10 // Clear the 'bullet' array, and allocate upto 100 bullets for the future, and when the array gets full, keep adding 10 more
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Hark0

Llego tarde... creo que ya está todo claro...

Saludos ;)

@Slydog  :good:
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

mentalthink

@Slydog
QuoteThat way you can use the convenience of dynamic arrays without worrying about GLBasic having to reallocate memory each time, which may slow things down.

Thanks I think whit this I have clear "reallocate memory each time, which may slow things down".

And well you propourse for the command it´s very interesting... but else, use a number for offset the Array, can be possible make don´t arrives to the index-n... if I arrives make somthing internally for the program don´t crash... I think it´s very very interesting you proporse... another thing it´s the time of Gernnot...

Hark0,
Pues nada más tarde he llegao yo, pero me ha quedao clara la cosa...

Saludos Hark0!!!
Greetings Slydog!!!