Raised This Month: $32 Target: $400
 8% 

How to use blocksize on ArrayList?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 10-17-2017 , 13:20   How to use blocksize on ArrayList?
Reply With Quote #1

I know that when I create an ArrayList I can specify a "blocksize", but when I push an value to the array there is any param to indicate the blocksize. How can I use the blocksizes?
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-17-2017 , 13:46   Re: How to use blocksize on ArrayList?
Reply With Quote #2

I rarely see anybody use blocksize unless it's for storing strings or using that old method of storing the enum containing information also. Just think of block size as the second element in a multi-deminsion arrray.
PushArray will fill the block size according to your set blocksize and array size, other than that you can use Set https://sm.alliedmods.net/new-api/ad.../ArrayList/Set
Mitchell is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 10-17-2017 , 13:54   Re: How to use blocksize on ArrayList?
Reply With Quote #3

So it's better to do:
PHP Code:
ArrayList array[10]; 
or
PHP Code:
ArrayList array = new ArrayList(10); 
?
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 10-17-2017 at 14:19.
Papero is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-17-2017 , 14:23   Re: How to use blocksize on ArrayList?
Reply With Quote #4

Probably the latter, depending on what you're using it for. The first will (potentially) create 10 new handles, the latter will create 1. However i'm unsure which would use up less memory.
I know for my UniqueChat plugin I create a StringMap for every player (when they join) and delete it after they leave to save space.
Mitchell is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-17-2017 , 15:34   Re: How to use blocksize on ArrayList?
Reply With Quote #5

Quote:
Originally Posted by Mitchell View Post
that old method of storing the enum containing information also
What's a better method, if not blocksize then?
__________________
retired
shavit is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 10-17-2017 , 20:17   Re: How to use blocksize on ArrayList?
Reply With Quote #6

Quote:
Originally Posted by Papero View Post
I know that when I create an ArrayList I can specify a "blocksize", but when I push an value to the array there is any param to indicate the blocksize. How can I use the blocksizes?
If you're pushing cells (handles, ints, floats) just use Push() with a blocksize of 1.
If you're pushing cell arrays use PushArray()
If you're pushing strings use PushString()

If the size of the array blocksize is < the size of the array when you push: The rest will be truncated. Set your blocksize accordingly. For example, if your storing player names the blocksize should be MAX_NAME_LENGTH.

If you're trying to mix and match the type of data you're pushing, there's probably a better data structure you should be using

Quote:
Originally Posted by Papero View Post
So it's better to do:
PHP Code:
ArrayList array[10]; 
or
PHP Code:
ArrayList array = new ArrayList(10); 
?
First one creates 10 null (empty/uninitialized) handles, the second one creates an ArrayList with a 10 blocksize

Quote:
Originally Posted by Mitchell View Post
However i'm unsure which would use up less memory.
The single ArrayList w/ blocksize 10 is a immensely better than 10 ArrayLists


Quote:
Originally Posted by shavit View Post
What's a better method, if not blocksize then?
Pretty sure there isn't a better method other than avoiding "enum structs" all together which I've subscribed to

Last edited by headline; 10-17-2017 at 20:19.
headline is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-17-2017 , 20:24   Re: How to use blocksize on ArrayList?
Reply With Quote #7

https://sm.alliedmods.net/new-api/ad...teCountToCells

PHP Code:
ArrayList array = new ArrayList(ByteCountToCells(MAX_NAME_LENGTH)); 
__________________
Do not Private Message @me
Bacardi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode