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 ??
LVL 10
smeggheadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Cheers!
0
leg1Commented:
create a class with the fields you want, create as many objects as you want, and then destroy them.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vettrangerCommented:
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.
0
smeggheadAuthor Commented:
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.
0
smeggheadAuthor Commented:
Old ZX81 / Spectrum basic eh ???

poke 35136,0

used to get infinite lives on Manic-Miner....  sad but true.
0
mcriderCommented:
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!
0
mcriderCommented:
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 


0
smeggheadAuthor Commented:
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...

0
phiroCommented:
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>
0
phiroCommented:
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>
0
phiroCommented:
Sorry 'bout that...
0
mcriderCommented:
Well if you insist on keeping the string, the answer to you question is no, there is no mem-mem moves to perform the task you want in VB.


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smeggheadAuthor Commented:
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 !!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.