flat assembler
Message board for the users of flat assembler.

Index > Main > Help with array and memory allocation

Author
Thread Post new topic Reply to topic
sakkiesalm



Joined: 07 Feb 2011
Posts: 9
sakkiesalm
hi There

I need some help.I have this structure

Code:
 struc MagicArray Index
 {
  .Index rq 102400
 }

My MagicArray    


But this allocates 819 kilo bytes and also makes my file grow larger by this size.
How do i allocate memory and set a pointer to use MagicArray.Index for example without having my file grow larger?

i do know about posix_memalign() but i do not understand how i will use that for example to point to this array.As soon as i put the code "My MagicArray" my filesize grows,and without this,how would i access my structure like i used to by my.Index for example?

Any help would be appreciated.Thanks
Post 25 Sep 2014, 11:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
See this recent topic for an explanation:
http://board.flatassembler.net/topic.php?t=17260

Moved to Main
Post 25 Sep 2014, 11:21
View user's profile Send private message Visit poster's website Reply with quote
sakkiesalm



Joined: 07 Feb 2011
Posts: 9
sakkiesalm
revolution wrote:
See this recent topic for an explanation:
http://board.flatassembler.net/topic.php?t=17260

Moved to Main


Thanks for the reply.I still do not understand how to apply this to the struc MagicArray.

Where do i place the dq instead of the rq so that it doesn't get added to the file.
I tried several combinations,shifting the struc,etc etc without any luck Sad
Post 25 Sep 2014, 11:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
You need to place the line "My MagicArray" at the end of a section.

The structure definition can be placed anywhere as long as it is before you instantiate it with "My MagicArray".
Post 25 Sep 2014, 15:49
View user's profile Send private message Visit poster's website Reply with quote
sakkiesalm



Joined: 07 Feb 2011
Posts: 9
sakkiesalm
revolution wrote:
You need to place the line "My MagicArray" at the end of a section.

The structure definition can be placed anywhere as long as it is before you instantiate it with "My MagicArray".


Thanks!
Post 26 Sep 2014, 06:59
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
it is not really good to instanciate large memory blocks in source code. better to use any malloc function to do the job, don't forget to free the memory at the end...

what do you think about that revolution?
Post 26 Sep 2014, 07:35
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
edfed: Like everything else it depends upon what you are doing. In general I would say that is reasonable advice for anything that one intends to use for a serious application. For quick-and-dirty though I guess it makes little difference, just don't tell anyone what you did and it will be fine.
Post 26 Sep 2014, 18:11
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
To allocate an array:
Code:
Array.P=Allocate(Array.N*Array.Scale)    
... where Array.Scale is the index/element size. Index would be: [S*I+Array.P] (SIB) or [Array.P+I*S] or Array.P[S*I] (all same, * is evaluated first). An easy way to remember is the word "PINS": Pointer, Index, Number, Scale:

* Array.P: Pointer, base address
* Array.I: Index
* Array.N: # indices
* Array.S: Index scale/size

New: Ultimate Visual Menus
Post 12 Oct 2014, 23:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.