# Na\_str-0.0.0 : combining narray with mmap for persistant num

**URL:** <https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286>\
**Category:** Ruby\
**Created:** [June 27, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286 "2006-06-27T22:41:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 27, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/1 "2006-06-27T22:41:18Z")

</div>

NAME

na\_str (c extension)

nmap (reference ruby class which combines narray and mmap)

URIS

[http://codeforpeople.com/lib/ruby/na\_str/](http://codeforpeople.com/lib/ruby/na_str/)

SYNOPSIS

na\_str is designed to allow data sharing between narray object and  
other ruby  
objects. the shared data is that returned by the objects to\_s or  
to\_str method  
and rb\_string\_new4. using this technique memory mapped (using guy’s  
mmap  
extensions) data can be altered with no explicit io on the users part  
and  
partial changed to numerical grids can occur very quickly and  
persistently.

the nmap.rb reference impl is a concrete example of this usage and is  
included in the distribution

EXAMPLE USAGE

```
 jib:~/eg/ruby/na_str > cat a.rb
 #
 # the nmap extension is installed along with na_str
 #
   require 'nmap'
 #
 # the NMap ctor interface is similar to NArray's, but a backing 

```

file must also  
# be specified  
#  
path, x, y = ‘int.data’, 3, 4  
nmap = NMap.int path, x, y  
#  
# copy the last row to the first  
#  
nmap.na[true, 0] = nmap.na[true, 3]  
#  
# set the last row to be the current time. if you run this a few  
times you’ll  
# notice that changes to the narray are automatically written to  
the to  
# backing file via the magic of mmap  
#  
nmap.na[true, 3] = Time.now.to\_i  
#  
# show the narray  
#  
p nmap.na

jib:~/eg/ruby/na\_str \> ruby a.rb  
NArray(ref).int(3,4):  
[[ 0, 0, 0],  
[0, 0, 0],  
[0, 0, 0],  
[1151439012, 1151439012, 1151439012] ]

jib:~/eg/ruby/na\_str \> ruby a.rb  
NArray(ref).int(3,4):  
[[ 1151439012, 1151439012, 1151439012],  
[0, 0, 0],  
[0, 0, 0],  
[1151439014, 1151439014, 1151439014] ]

SPEED

jib:~/eg/ruby/na\_str \> cat a.rb

# 

# reference impl installed with na\_str

# 

```
 require 'nmap'

```

# 

# setup a narray grid containing 1 gb of ints

# 

```
 gb = 2 ** 30
 mb = 2 ** 20
 sizeof_int = [42].pack('i').size
 gig_of_ints = gb / sizeof_int
 nmap = NMap.int '1GB', gig_of_ints

```

# 

# set about 1 million of the ints to 42

# 

```
 nmap.na[0 .. mb] = 42

```

# 

# show that the data was written

# 

```
 p nmap.na[mb - 1]

```

jib:~/eg/ruby/na\_str \> time ruby a.rb  
42

real 0m0.078s  
user 0m0.020s  
sys 0m0.020s

jib:~/eg/ruby/na\_str \> ls -ltar 1GB  
-rw-rw-r-- 1 ahoward ahoward 1073741824 Jun 27 14:28 1GB

this an experimental package - thank to matz for the tip on rb\_str\_new4.

enjoy.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 28, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/2 "2006-06-28T19:39:29Z")

</div>

On 6/27/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> this an experimental package - thank to matz for the tip on rb\_str\_new4.
> 
> enjoy.

Ara, for the uninitiated among us, could you please explain what  
rb\_str\_new4 does exactly? Also, what is the ELTS\_SHARED flag  
signifies and in what circumstances should it be used?

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 29, 2006, 1:20am UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/3 "2006-06-29T01:20:45Z")

</div>

Hi,

In message “Re: [ANN] na\_str-0.0.0 : combining narray with mmap for  
persistant numerical data”  
on Thu, 29 Jun 2006 02:14:34 +0900, “Tim P.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|Ara, for the uninitiated among us, could you please explain what  
|rb\_str\_new4 does exactly? Also, what is the ELTS\_SHARED flag  
|signifies and in what circumstances should it be used?

rb\_str\_new4() creates a new string that shares internal memory region  
with the original. ELTS\_SHARED means the string is sharing memory  
region with other string object.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 30, 2006, 2:37am UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/4 "2006-06-30T02:37:50Z")

</div>

On Fri, 30 Jun 2006, Joel VanderWerf wrote:

> $ man nmap  
> …  
> nmap - Network exploration tool and security scanner  
> …

i open to suggestion - ideas? this first one was just a whack at it  
anyhow -  
but it’s already pretty useful.

cheers.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 30, 2006, 2:10am UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/5 "2006-06-30T02:10:11Z")

</div>

removed\_email\_address@domain.invalid wrote:

> NAME
> 
> na\_str (c extension)
> 
> nmap (reference ruby class which combines narray and mmap)

This is very cool, but won’t the name be confusing?

$ man nmap  
…  
nmap - Network exploration tool and security scanner  
…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 30, 2006, 2:44am UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/6 "2006-06-30T02:44:17Z")

</div>

On Fri, 30 Jun 2006, Joel VanderWerf wrote:

> $ man nmap  
> …  
> nmap - Network exploration tool and security scanner  
> …

maybe na\_map?

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 1, 2006, 12:01pm UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/7 "2006-07-01T12:01:28Z")

</div>

removed\_email\_address@domain.invalid writes:

> > This is very cool, but won’t the name be confusing?
> > 
> > $ man nmap  
> > …  
> > nmap - Network exploration tool and security scanner  
> > …
> 
> maybe na\_map?

What about ActiveMMappedNArray? _scnr_.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 1, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/na-str-0-0-0-combining-narray-with-mmap-for-persistant-num/96286/8 "2006-07-01T15:16:35Z")

</div>

On Sat, 1 Jul 2006, Christian N. wrote:

> > > > nmap (reference ruby class which combines narray and mmap)
> 
> What about ActiveMMappedNArray? _scnr_.

heh.

i’ll count that as na\_map +1 then 😉

-a
