• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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 ??
0
smegghead
Asked:
smegghead
  • 4
  • 4
  • 3
  • +3
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 4
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now