digitalmars.D.learn - convert *void to void[]
- gabrielsylar (3/3) May 06 2009 can anybody please tell me how to properly convert from void* to void[]
- TSalm (4/7) May 06 2009 Something like could works :
- TSalm (3/11) May 06 2009 Forget my example, it's wrong.
- Robert Fraser (13/17) May 06 2009 void[] has a length, so you have to know the length. Assuming the length...
- John C (2/6) May 06 2009 return sqlite3_column_blob(stmt, n)[0 .. n];
- gabrielsylar (4/12) May 06 2009 int i=sqlite3_column_bytes(stmt, n);
- downs (3/7) May 06 2009 In unrelated matters: if you're writing a sqlite3 binding, take a look a...
- gabrielsylar (2/11) May 06 2009 thanks, but im writing my own simple wrapper around sqlite3.dll(so) dyna...
can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }
May 06 2009
Le Wed, 06 May 2009 10:17:47 +0200, gabrielsylar <noreply email.com> a écrit:can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }Something like could works : return *( cast(void[]*) sqlite3_column_blob(stmt, n) ) ;
May 06 2009
Le Wed, 06 May 2009 10:33:33 +0200, TSalm <TSalm free.fr> a écrit:Le Wed, 06 May 2009 10:17:47 +0200, gabrielsylar <noreply email.com> a écrit:Forget my example, it's wrong. Sorry.can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }Something like could works : return *( cast(void[]*) sqlite3_column_blob(stmt, n) ) ;
May 06 2009
gabrielsylar wrote:can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }void[] has a length, so you have to know the length. Assuming the length is n... Maybe try something like this (untested): struct DynArray { public void* ptr; public size_t length; public T[] toArray(T)() { return cast(T[]) cast(void*) (*this); } } void[] get_bytes(int n) { return DynArray(sqlite3_column_blob(stmt, n), n).toArray!(void); }
May 06 2009
gabrielsylar Wrote:can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }return sqlite3_column_blob(stmt, n)[0 .. n];
May 06 2009
John C Wrote:gabrielsylar Wrote:int i=sqlite3_column_bytes(stmt, n); return sqlite3_column_blob(stmt, n)[0 .. i]; thanks, it works. and much simpler than i toughtcan anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }return sqlite3_column_blob(stmt, n)[0 .. n];
May 06 2009
gabrielsylar wrote:can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }In unrelated matters: if you're writing a sqlite3 binding, take a look at tools.sqlite3. :) http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d
May 06 2009
downs Wrote:gabrielsylar wrote:thanks, but im writing my own simple wrapper around sqlite3.dll(so) dynamic loadable librarycan anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }In unrelated matters: if you're writing a sqlite3 binding, take a look at tools.sqlite3. :) http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d
May 06 2009