Jump to content
  • Advertisement
Sign in to follow this  
Lord Chiko

Pointers (VB6/VC6++)

This topic is 4340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, all I'm developing a program in VB that sends information to a C++ Dll i want the c++ to process this information and store it into a string (this string is currently at 2MB) i then want c++ to return a pointer to VB and have VB copy this pointer to a local byte array preferably using copymemory the problem i am having is im not sure how to find the pointer of a variable in c++ and im not sure how to use the pointer in vb without crashing it ^_^ char* temp = new char[2000000]; ^ That is the variable i will be using to send to visual basic Also is there a better method of doing this? im aiming for real time 2MB doesn't seem to much to send but i may be mistaken ty all in advanced

Share this post


Link to post
Share on other sites
Advertisement
I figure i may aswell explain exactly what im trying to do

I want to create an api that i can call from visual basic which will basically

send to c++ several pointers to several byte arrays (or can be strings if really needed)

these pointers will be linked to

character frames like their byte data (captured with dibits)

and the screen its self

c++ will also receieve a list of the locations that c++ needs to draw to (copying the frame data to the screen array)

im thinking of doing it by reference however if its 2 slow then i will have a temporary array (suggested in previous post) do all the modifcations there

then send a pointer to visual basic so it may copy the data from the array to the screen array and then be drwan by dibits ^_^

Share this post


Link to post
Share on other sites
2 MBytes of data, suppose at 100 times per second, is about 2 GigaBits/second of data movement.

This is a non-trivial fraction of the memory bandwidth availiable on a half-decent modern PC.

Modern PCs range from 5 to 20 GBits/second of read/modify/write bandwidth. So 2 MBytes @ 100 HRz uses up between 10% and 40% of the system's memory bandwidth, assuming the computer is doing nothing else.

In other words, this is a heck of alot of data to be throwing around on a per-frame basis, especially within visual basic.

Share this post


Link to post
Share on other sites
Quote:
Original post by NotAYakk
2 MBytes of data, suppose at 100 times per second, is about 2 GigaBits/second of data movement.

This is a non-trivial fraction of the memory bandwidth availiable on a half-decent modern PC.

Modern PCs range from 5 to 20 GBits/second of read/modify/write bandwidth. So 2 MBytes @ 100 HRz uses up between 10% and 40% of the system's memory bandwidth, assuming the computer is doing nothing else.

In other words, this is a heck of alot of data to be throwing around on a per-frame basis, especially within visual basic.



well it is for a game ^_^ what im not sure about is why 2MB be alot to copy where i can write upto 800MB a second worth of data

not exactly 800MB just writing 19KB to random spots within a 2MB array 40,000 times a second and yeah

the game will (preferably) be capped at 30 FPS so really only 60MB of the bandwidth should be used per second

However i am aiming at low end machines so is there any alternative to doing what i want? (c++ creates byte array - vb draws the byte array)

Share this post


Link to post
Share on other sites
Why are you copying the data back and forth? Just pass the pointer to C++ and it can directly access the data.

It's been a while since I've programmed in VB, but I believe this is basically what you should do. If I'm wrong about this, just disregard..

In VB code:

Dim a(2000000) as Byte

SomeCallToTheDLL(VarPtr(a(0)))

In C++:

void SomeCallToTheDLL(Char *a) {
a[56354] = 'h';
// more stuff here
}

Share this post


Link to post
Share on other sites
Quote:
Original post by tendifo
Why are you copying the data back and forth? Just pass the pointer to C++ and it can directly access the data.

It's been a while since I've programmed in VB, but I believe this is basically what you should do. If I'm wrong about this, just disregard..

In VB code:

Dim a(2000000) as Byte

SomeCallToTheDLL(VarPtr(a(0)))

In C++:

void SomeCallToTheDLL(Char *a) {
a[56354] = 'h';
// more stuff here
}



ok ty ill give it ago the problem that stopped me doing this last time was that it was incredible slow i think vb was interacting with the data everytime i changed it but i probly did something wrong ty ^_^

ill let you all know how it goes

Share this post


Link to post
Share on other sites
Thank you tendifo it works flawlessly it is able to modify 2MB worth of data 600 Times a second which is beyond what i need (30) 20 times more power can't hurt :D for those interest this is the visual basic code i've used

Private Declare Function GetNumberEX Lib "GraphicsEX.dll" (ByVal x As Long, ByVal y As Long, ByVal Data As Long) As Long

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()
Dim a(1 To 2000000) As Byte
s = GetTickCount

For x = 1 To 600
GetNumberEX 0, 0, VarPtr(a(1))
Next x

e = GetTickCount
MsgBox e - s
End Sub


also the code in c++ (i'll only post the part doing any work)

for (long xx=0;xx<=1999999;xx++)
{
a[xx] = 255;
}

im going to install several functions that being the 1 to clear the screen ^_^

so yeah ty very much ill check back with any troubles i have

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!