Link to home
Start Free TrialLog in
Avatar of smegghead
smeggheadFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Memory Allocation using VB

Is is possible to allocate a chunk of memory, then read/write bytes from it or copy chunks to and from..

I'm sure you can do this with C++ pointers etc, but I've never seen it done in VB ??
Avatar of KDivad
KDivad

You can (I think) allocate memory using GlobalAlloc (API), but I don't think you can do the read/write you are wanting...
I'm curious... why do you need to do this??

Cheers!
create a class with the fields you want, create as many objects as you want, and then destroy them.
DOS Basics used to do the memory access part of that with Peek and Poke, but I think that's out of the language now in favor of API calls.
Avatar of smegghead

ASKER

I'll explain what I'm doing, in simple terms...

I've got a string, can be very long... it contains text in the following format.

smegghead~leg1~mcrider~kdavid

I need to sort the elements within string into alphabetical order. So I'm doing a bubble-sort through the string. For example if smegghead > leg1 then swap the elements and so on.... At the moment, I'm using left$ & mid$, trouble is is that when the string gets very long, it becomes very slow because the entire string has to be copied to memory every time you make a change to it.

x=left$(x,pos1-1) & second & "~" & first & mid$(x,pos2+len(second))

I've just typed that straight in, so bear with me on the syntax and accuracy.

So, it would be more efficient if you could allocate a block of memory and just say...

memwrite pos1, second & + "~"
memwrite pos1+len(second)+2, first

I've already done this using the above method (left$ & mid$) and it works fine, I just thought that I could speed up the process by avoiding copying entire strings in and out of memory.

The above example is entirely ficticious... so I don't need a work arounds on this.
Old ZX81 / Spectrum basic eh ???

poke 35136,0

used to get infinite lives on Manic-Miner....  sad but true.
why not convert the string into an array and do a bubble sort on it...

FILE: How to Sort Algorithms for Numeric Arrays
http://support.microsoft.com/support/kb/articles/Q169/6/17.asp

Cheers!
If you click on the URL in the answer I gave it will not work (EE BUG!) That reference should be:

http://support.microsoft.com/support/kb/articles/Q169/6/17.asp 


mcrider,

Thanks for your comments,but... see the end of my last comment.

'The above example is entirely ficticious... so I don't need a work arounds on this'

I know various ways of speeding up the example I gave you, but it was just an example. Hence no work-arounds...

Well , only way around this would be to write the code in C(++) and then compile it into a dll, then use it from VB.

VB itself does not allow direct calls to memalloc other than through winapi's or dll's.



poke 4839,1 sometimes blow up the tv connected to a commandore 64...
Viral code meaning someting those days <eg>
Well , only way around this would be to write the code in C(++) and then compile it into a dll, then use it from VB.

VB itself does not allow direct calls to memalloc other than through winapi's or dll's.



poke 4839,1 sometimes blow up the tv connected to a commandore 64...
Viral code meaning someting those days <eg>
Sorry 'bout that...
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bring back peek/poke...

mcrider, thanks for your advice.

phiro, is that difficult, writing a c++ function which can be used within VB ??? I did a brief course in c++ a few years back, but never really had any cause to use it. I've seen the recent version of c++ (which ships with VB6) and it's got loads of wizards'n'stuff, maybe I'll try to get into it..

Leg1, are you on the right question ???

kdavid, ta !!