[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gambas-bugtracker] Bug #3143: Structure size calculations seem off , varptr to structure do not return a pointer to data area


http://gambaswiki.org/bugtracker/edit?object=BUG.3143&from=L21haW4-

Comment #5 by Brian G:

as an example, similar example is included in the sample app provided

public struct mystruct
  a as integer
  b as long
  d as float
end struct

dim a as pointer = alloc(2000)
dim b as struct mystruct 
b=a                             ' assign the memory address returned by alloc to the structure
dim c as pointer
c=varptr(b)                     ' c now equals a the memory address assigned to the structure

In the provided app look at the root variable, it implements this

---------------------------------------------------------------------------

Ok as far as memcopy goes i was using it as a simple example of calling a c function, it could be any function

example given two structures that perhaps need to be copied to a system area i need to do the following

public struct astruct
   a as integer
end struct
public struct bstruct
   a as float
end struct

dim a as new struct astruct
dim b as new struct bstruct

' now to copy these using memcpy to a system buffer for instance, I need to redefine memcpy to accept each struct type, rather than just define a pointer
Extern amemcpy(from As astruct, to As astruct, length As Integer) As Pointer In "libc:6" Exec "memcpy"
Extern bmemcpy(from As bstruct, to As bstruct, length As Integer) As Pointer In "libc:6" Exec "memcpy"

' uselesslly copy over self as an example, you could replace in this example memcpy with any c call taking structures that are buffers
amemcpy(a,a,0)
bmemcpy(b,b,0)

The provided app gives an example of this as well



----[ Gambas bugtracker-list is hosted by https://www.hostsharing.net ]----