mIRC Home    About    Download    Register    News    Help

Print Thread
#216732 29/11/09 04:48 PM
Joined: Nov 2009
Posts: 81
V
Voglea Offline OP
Babel fish
OP Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
Code:
alias file2ram {

  ; any file, example mirc.exe
  tokenize 32 mirc.exe

  ; free table, if exists
  if ($hget($1)) hdel -w $1 *

  ; read file to hash table (RAM)
  var %i = 0, %s = $file($1)
  while (%i <= %s) {
    bread $1 %i 4096 $+(&,$1)
    hadd -mb $1 $calc($hget($1,0).item + 1) $+(&,$1)
    bunset $+(&,$1)
    inc %i 4096
  }

  ; we have 100% mirc.exe in RAM -> hash table "mirc.exe"
  echo -a total $hget($1,0).item pieces, 1 piece <= 4096 bytes

  ; and now I need to send this file, from RAM by sockets
  ; sending "mirc.exe" hash table
  sendfile $1
}

; ...socket already open
alias sendfile {
  ; ??? :(
  ; as lamers example:

  var %i = 1
  while (%i <= $hget($1,0).item) {
    if ($hget($1,%i,$+(&,$1))) {
      sockwrite any_sockname $+(&,$1)
      bunset $+(&,$1)
    }
    inc %i
  }
  ; it's not working

  ; help please! =(
}

Last edited by Voglea; 29/11/09 04:49 PM.
Voglea #216746 30/11/09 04:54 PM
Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Don't make the mistake of thinking that this is in RAM -- it could be deemed virtual memory (heap memory migrated to the hard disk) later on. You're putting way too much emphasis in efficiency by using hashtables to cache reads, and developing a script which isn't guaranteed to be as efficient as it could be in the future (or indeed the present). Solid state drives and current caching are likely to do a far better job of this. Of course, if you're still convinced this is the right way to go about it, just create a RAMDISK. Delegate it to an existing and mature module that is precisely designed for the purpose. That way you can be sure when your code is rendered inelegant and inoptimal, you'll be able to optimize it more easily.

This looks sus: tokenize 32 mirc.exe
You have $1 elsewhere. Is this going to be 'an example' or an actual function? Make up your mind.

You seem to be confused about the usage of hashtables. There are 2 ways you can access the items within them: by numeric index and by key. Don't assume that your items will be in the order you added them to the collection in, if you access by numeric index. More information here: /help hashtables.


Link Copied to Clipboard