mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
A way to return the amount of bytes that a &binvar, stored in a hashtable is, without mIRC copying the data stored, into another block of memory.



I am SReject
My Stuff
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
I believe $hget(<table>,<item>,<&bvar>) returns the size of the bvar.


Beware of MeStinkBAD! He knows more than he actually does!
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
*sigh*, he said without copying it into another block of memory.


...though it's unclear if $hget() even does a memory copy for bvar assignment.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
From the help file for mIRC 6.35 under /help $hget
Quote:
$hget(name/N, item, &binvar)

Assigns the contents of an item to a &binvar.



However, if I'm understanding the suggestion correctly, this isn't relative.

Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
First off, I said WITHOUT copying it into another block of memory. The way I know It does, is try this:
Code:
bset -t &test 1 this is a test
hadd -mb table item &test
bset -t &test 15 to see if the var in the hash table changed
echo If $!hget() doesn't copy the binvar into another block of memory the following should be the same:
echo $bvar(&test,1-).text
noop $hget(table,item,&test2)
echo $bvar(&test2,1-).test
hfree table

If $hget() just returned a reference to the &binvar, then when editing &test, the item in the hashtable would change.



I am SReject
My Stuff
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
"relative"? to what?

The description in the help does not explicitly say whether it's copying or passing by reference. You wouldn't expect that kind of implementation detail to be discussed anyway.



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
That doesn't necessarily prove anything; it could be doing lazy-copies for binvars from hash tables. It's also feasible that all binvars could be immutable, and any /bset or binary operation would result in a new copy, meaning it could just pass the hash table binvar by memory reference (to that specific copy only).

That said, mIRC's engine rarely has performance optimizations like those, so it's probably safe (enough) to assume that it does do a copy- it's just unclear.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Storing a 100,000,000 byte binvar in bstore, the following causes a memory error... hence $hget (and likely all &binvar commands) copy the variable rather than pass it by reference.

Code:
//output -a $hget(bstore,&v1,&v01) $hget(bstore,&v1,&v02) $&
$hget(bstore,&v1,&v03) $hget(bstore,&v1,&v04) $&
$hget(bstore,&v1,&v05) $hget(bstore,&v1,&v06) $& 
$hget(bstore,&v1,&v07) $hget(bstore,&v1,&v08) $& 
$hget(bstore,&v1,&v09) $hget(bstore,&v1,&v10) $& 
$hget(bstore,&v1,&v11) $hget(bstore,&v1,&v12) $& 
$hget(bstore,&v1,&v13) $hget(bstore,&v1,&v14)


Hence working with &binvars of this size is SLOW...



Beware of MeStinkBAD! He knows more than he actually does!
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Here I was working on these custom functions to handle binvar storage... more work is needed...

Code:
;** /_BSTORE [-suN] &binvar
ALIAS _BSTORE {
  var %flags, %bvar, %verbose

  if (!$hget(BSTORE)) { /hmake BSTORE 1000 }

  if ($parseflags($1,su)) { %flags = $v1 | %bvar = $2- }
  else { %bvar = $1- }

  if (!$len(%bvar)) { return -1 }
  if ($bvar(%bvar,0) == 0) { /hdel -s BSTORE %bvar | return }

  if (-s isin %flags) {
    %verbose = $true
  }

  if (-u isin %flags) {
    tokenize 32 %flags

    while (-u* !iswm $1) { if (!$len($1)) break | tokenize 32 $2- }

    %flags = $+($1,$iif($1,b,-b))
  }
  else {
    %flags = -b
  }

  if (%verbose) { /output INFO2 -ape Storing $bvar(%bvar,0) byte binary var $bo($upper(%bvar)) $+ . }

  /hadd %flags BSTORE %bvar %bvar
}

;** $_bget(<&binvar|N>).prop
;**  Properties: size, unset
ALIAS _BGET {
  var %size, %i, %bvar
  if (!$hget(BSTORE)) { /hmake BSTORE 1000 }

  if ($1 == 0) && ($prop == size) {
    %i = 0
    %size = 0
    while (%i < $hget(BSTORE,0).item) {
      inc %i
      %bvar = $hget(BSTORE,%i).item
      %size = %size + $hget(BSTORE,%bvar,%bvar)
    }
    return %size
  }

  if ($prop == unset) $&
    return $hget(BSTORE,$1).unset

  if ($hget(BSTORE,$1).item) { %bvar = $hget(BSTORE,$1,$hget(BSTORE,$1).item).item }

  if ($prop == size) { return $hget(BSTORE,%bvar,%bvar) }
  else { return $hget(BSTORE,%bvar).item }
}


NOTE: OUTPUT/$PARSEFLAGS are custom commands/identifiers...

Last edited by MeStinkBAD; 28/07/10 04:33 AM.

Beware of MeStinkBAD! He knows more than he actually does!

Link Copied to Clipboard