Initializing matrices with given SQL data
#1

Hi, since pawn does not have dynamic arrays or matrices I need a clue on how to do this (what title says), can you help me?

What I need to do is read something from a SQL database (actually I know how to do this) and then store it in a [n][m] matrix, where n is the index of the row and m are the number of data fields, 'n' and 'm' are not constant values (and there is my problem, the size values for a array or a n-dimensional array are always constant values in pawn), specially n.

The fact is avoid any kind of memory waste or unnecesary memory usage, because the only solution I've thought and makes sense to me is making sufficiently big arrays to ensure there always be enough space to store data from an always-changing database data.

Thanks in advance for read and if you have any kind of solution for my problem please reply this topic.
Reply
#2

What exactly is this being used for? It's not possible to create dynamic arrays in PAWN (but IS in plugins). The only way to use dynamic memory in PAWN is PVars which aren't really suitable for what you need.

I'd look in to plugins if you have some C++ experience. Sounds like a good idea for a plugin to me.
Reply
#3

Quote:
Originally Posted by MP2
Посмотреть сообщение
What exactly is this being used for? It's not possible to create dynamic arrays in PAWN (but IS in plugins). The only way to use dynamic memory in PAWN is PVars which aren't really suitable for what you need.

I'd look in to plugins if you have some C++ experience. Sounds like a good idea for a plugin to me.
Yes, pawn has not dynamic arrays, and plugin creation could be a good idea. I am not so experienced in c++, but knowing another OOP languages I think I can learn this language deeply.

My idea is to store dynamic created objets, sorted by tables (RP case: houses, cars, stats of factions, businesses stuff; DM/freeroam case: Clan stats, events stats, car info)
Reply
#4

Try this, it's the whole vector memory structure from c++. IMO, you shouldn't be worried about it all all, using that plugin might not be practical because modern PC's can handle memory.
Reply
#5

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Try this, it's the whole vector memory structure from c++. IMO, you shouldn't be worried about it all all, using that plugin might not be practical because modern PC's can handle memory.
So, you think that is better to use big pre-sized arrays than use this plugin?
Reply
#6

I would rather use big pre-sized arrays (not saying dynamic memory isn't awesome). Logically, it would seem slower to have to interact with memory using a plugin.

I'm not going to speak for you though, do your own benchmarks.
Reply
#7

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
I would rather use big pre-sized arrays (not saying dynamic memory isn't awesome). Logically, it would seem slower to have to interact with memory using a plugin.

I'm not going to speak for you though, do your own benchmarks.
And you're right... I could make an iteration trough indexes initializing the pre-declared items, letting some extra empty items in the matrix if I need to add something in-game.
Reply
#8

You could also just set the array to a realistic size. For example, houses. You could set it to something like 40 or 50, keep a close eye on it with a command of some sort then just re-compile and restart if you need more.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)