For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > December 2005 > How to merge two array without for loop assigment









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to merge two array without for loop assigment
Boki

2005-12-13, 9:55 pm

Hi All,
I want to merge (collect) the MScomm control's input data.

Buffer = mscomm1.input

but the next time I assign it again, the prevous data will be clear (
ReDim), but I want to collect them ( because that is a jpg stream )

Could you please advice ?

Best regards,
Boki.


alpine

2005-12-14, 6:57 pm

On Wed, 14 Dec 2005 10:06:48 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote:

>Hi All,
> I want to merge (collect) the MScomm control's input data.
>
>Buffer = mscomm1.input
>
>but the next time I assign it again, the prevous data will be clear (
>ReDim), but I want to collect them ( because that is a jpg stream )
>
>Could you please advice ?
>
>Best regards,
>Boki.



If you are using a byte array for your buffer, you can copy it's
contents to another (larger) array using the CopyMemory API function.
You can track the "next write" position in the larger array and then
write the next chunk of data to that position and then increment the
pointer for the next write.

HTH,
Bryan
_______________________________
Bryan Stafford
New Vision Software
newvision_don'tspam@mvps.org
Boki

2005-12-14, 6:57 pm

Ya, byte array.

CopyMemory, I got it! Thanks a lot! :D

Best regards,
Boki
"alpine" <alpine_don'tsendspam@mvps.org>
???????:jcc0q19visurt6disdusb7uh74f74ohkrn@4ax.com...
> On Wed, 14 Dec 2005 10:06:48 +0800, "Boki" <bokiteam@ms21.hinet.net>
> wrote:
>
>
>
> If you are using a byte array for your buffer, you can copy it's
> contents to another (larger) array using the CopyMemory API function.
> You can track the "next write" position in the larger array and then
> write the next chunk of data to that position and then increment the
> pointer for the next write.
>
> HTH,
> Bryan
> _______________________________
> Bryan Stafford
> New Vision Software
> newvision_don'tspam@mvps.org



J French

2005-12-15, 7:55 am

On Thu, 15 Dec 2005 00:06:36 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote:

>Ya, byte array.
>
>CopyMemory, I got it! Thanks a lot! :D


To be honest, when compiled, just moving Bytes in Byte Arrays is
incredibly fast
- you would probably be better off not using the APIs for the time
being
bokiteam@ms21.hinet.net

2005-12-15, 6:55 pm

Why ?
I think API is always faster ..

for example

bitblt ,

isn't it ?

Best regards,
Boki.

Rick Rothstein [MVP - Visual Basic]

2005-12-15, 6:55 pm

> > Why ?
>
> I think API is always faster ..
> isn't it ?


Yes, but if that is your criteria, why are you programming in VB instead of
something that is always faster, like Assembly Language?

Rick


Dmitriy Antonov

2005-12-15, 6:55 pm


"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote in message news:ehCClxZAGHA.3456@TK2MSFTNGP11.phx.gbl...
>
> Yes, but if that is your criteria, why are you programming in VB instead
> of
> something that is always faster, like Assembly Language?
>
> Rick
>
>


In addition, it is not always faster. It is like saying that "airplane is
the fastest way to commute from A to B". But what if B is your local store,
or it is the town near your airport?

For example statement i=10 can be re-factored to be done with CopyMemory but
it will be much more slower.
Copying one aray to another by direct assignment should take less or similar
time as CopyMemory.

However, IMO, in case of OP, where loop should be involved, using CopyMemory
can give some advantage, which can be noticeable, when number of copied
elements is descent.

Dmitriy.


Boki

2005-12-15, 9:55 pm

Thanks for information. I will study it more :)

Best regards,
Boki.



"Dmitriy Antonov" <antonovdima@netzero.net_NOT_FOR_SPAM> 撰寫於郵件新聞:OOifaAaAGHA.916@TK2MSFTNGP10.phx.gbl...
>
> "Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
> wrote in message news:ehCClxZAGHA.3456@TK2MSFTNGP11.phx.gbl...
>
> In addition, it is not always faster. It is like saying that "airplane is
> the fastest way to commute from A to B". But what if B is your local
> store, or it is the town near your airport?
>
> For example statement i=10 can be re-factored to be done with CopyMemory
> but it will be much more slower.
> Copying one aray to another by direct assignment should take less or
> similar time as CopyMemory.
>
> However, IMO, in case of OP, where loop should be involved, using
> CopyMemory can give some advantage, which can be noticeable, when number
> of copied elements is descent.
>
> Dmitriy.
>



Boki

2005-12-15, 9:55 pm

so, you think MemoryCopy is faster than merge two arrays by for loop
assignment?

and

I like to optimaize everything. : )

Best regards,
Boki.


"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net> 撰寫於郵件新聞:ehCClxZAGHA.3456@TK2MSFTNGP11.phx.gbl...
>
> Yes, but if that is your criteria, why are you programming in VB instead
> of
> something that is always faster, like Assembly Language?
>
> Rick
>
>



Rick Rothstein [MVP - Visual Basic]

2005-12-15, 9:55 pm

> >> I think API is always faster ..
> so, you think MemoryCopy is faster than merge two arrays by
> for loop assignment?


The point of my comment was that you have chosen to program in VB which, by
its very nature, is slower than lots of other language alternatives. You
need to accept that. Yes, there are occasions (not as many as you might
think) when you need to try to optimize the hell out of a code segment, but
doing so for any and every piece of code is overkill in the extreme. Most of
your program will be waiting for the user to react and then do something
(that is the nature of event driven programming), you do not need to
optimize the code around these sections... even if there are faster API
alternatives available.

> I like to optimaize everything. : )


Then you will be wasting a lot of your time wringing out performance gains
that, for the vast majority of cases, no one will see.

Rick


Boki

2005-12-15, 9:55 pm

Thank you very much.
I am using VB to prove a prototype.
When I proved it, I will code it as VC6. If possible I also want to code it
as .NET ( depend on time )

Why I use VB ? I think the reason is very simple, it save me a lot of time
to deal with WIN32/GUI stuff..

Originally, I code it in J2ME, the CPU of phone is not as fast as PC, so I
have to care almost every line of code to optimize the FPS( frame per
sercond ) in my app.

I have not finished the VB version yet, if my program can't satisify 30 fps,
that means I have to optimize it finally, because I don't have enough time
to code it as VC now. ( The main reson is I am not familiar with WIN32 GUI
programming ... I don't have enough time to study yet ....: ), but VB can
help me a lot directly)

:)

Best regards,
Boki.





"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net> 撰寫於郵件新聞:u20SseeAGHA.3804@TK2MSFTNGP14.phx.gbl...
>
> The point of my comment was that you have chosen to program in VB which,
> by
> its very nature, is slower than lots of other language alternatives. You
> need to accept that. Yes, there are occasions (not as many as you might
> think) when you need to try to optimize the hell out of a code segment,
> but
> doing so for any and every piece of code is overkill in the extreme. Most
> of
> your program will be waiting for the user to react and then do something
> (that is the nature of event driven programming), you do not need to
> optimize the code around these sections... even if there are faster API
> alternatives available.
>
>
> Then you will be wasting a lot of your time wringing out performance gains
> that, for the vast majority of cases, no one will see.
>
> Rick
>
>



J French

2005-12-16, 3:55 am

On 15 Dec 2005 09:04:53 -0800, bokiteam@ms21.hinet.net wrote:

>Why ?
>I think API is always faster ..
>
>for example
>
>bitblt ,
>
>isn't it ?


Sometimes APIs are faster
- it is not totally guaranteed

However manipulating elements in a Byte Array is incredibly fast in
compiled VB
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com