Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails NOT SOLVED

  • From: Patrick Masotta <masottaus@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 21 Jun 2012 04:05:08 -0700 (PDT)

You guys are right..  I was having memory issues...
 
this is somehow inconsistent...
 
local var_01 = ffi.new("char[5]", "default string value for var_01" );
only load the first 4 char + \0;  that's logic
 
but 
local var_01 = ffi.new("char[?]",0, "default value for var_01" ); 
copies the whole thing w/o allocating??
 
It would be good catching the 0 thing or convering it into the feature I 
thought it was
Does anyone knows where in LJ source code is this implemented?
 
thanks
 
 
 
 
 
 

--- On Thu, 6/21/12, Robert G. Jakabosky <bobby@xxxxxxxxxxxxxxx> wrote:


From: Robert G. Jakabosky <bobby@xxxxxxxxxxxxxxx>
Subject: Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails SOLVED
To: luajit@xxxxxxxxxxxxx
Date: Thursday, June 21, 2012, 3:39 AM


On Thursday 21, Patrick Masotta wrote:
> local buf = ffi.new("char[?]", 0, "HELLO WORLD")  does the trick

Don't do that you are corrupting memory.  See that attached script.

-- 
Robert G. Jakabosky

Other related posts: