C # Memory replication and array replication examples

Source: Internet
Author: User

Memory Copy-marshal.copy:

Copy the current incoming data
 byte[] pcm_src = new Byte[len];
 Copy data to binary array
 marshal.copy (PCM, PCM_SRC, 0, Len);

Array replication-array.copy:

Copy the current incoming data
byte[] pcm_src = new Byte[len];
Copy data to binary array
marshal.copy (PCM, PCM_SRC, 0, Len);
Copy the new incoming data to the new array structure
array.copy (pcm_src, 0, Pcm_dest, Bts_left. Length, Len)

Test Example:

        Sample number ushort samples = 320;

        Last remaining bytes byte[] bts_left;
            Class AA {public byte[] PCM;
        public int len;
    
        Private list<aa> data = new list<aa> ();  public void Playaudio (IntPtr pcm, int len) {lock (this) {int Samples_len

                = samples * 2;
                    if (len = = Samples_len) {byte[] BTS = new Byte[len];
                    Marshal.Copy (PCM, BTS, 0, Len); Data.
                    ADD (new AA {len = len, PCM = BTS
                }); else//Here resolve the size of the partition to replicate data when the sample number is 1024 {var len_temp = BT S_left ==null? Len:len + bts_left.

                    Length;
                    byte[] pcm_dest = new Byte[len_temp]; byte[] BTS = new Byte[samples_Len];
                        Copy data if (Bts_left!= null) {//Copy length not enough data Array.copy (bts_left,0, pcm_dest, 0, Bts_left.
                        Length);
                        Copy the current incoming data byte[] pcm_src = new Byte[len];
                        Copy data to binary array marshal.copy (PCM, PCM_SRC, 0, Len); Copy the new incoming data to the new array structure array.copy (PCM_SRC, 0, Pcm_dest, Bts_left.
                       
                        Length, Len);
                    Bts_left = null;
                    else {marshal.copy (PCM, pcm_dest, 0, len_temp);
                    //Get playback data int index = 0,count= Len_temp/samples_len;
                    int startindex=0; Console.WriteLine (">>>total:" + len_temp + ", Times:" + Count + ", left:" + len_temp% SamplEs_len); while (index< count) {//Copy the data array.copy that satisfies the length (pcm_
                        Dest, StartIndex, BTS, 0, Samples_len); Add data.
                        ADD (new AA {len = Samples_len, PCM = BTS
                        });
                        index++; 
                    Calculates the next start position StartIndex = index * SAMPLES_LEN;
                    }///staging length not enough data var Left_len = len_temp% Samples_len;
                        if (Left_len > 0) {bts_left = new Byte[left_len];
                    Replication is not long enough for data array.copy (Pcm_dest, StartIndex, Bts_left, 0, Left_len); }}//sdl.
        Sdl_delay (10); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.