473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Return Byte[] : reference or value?

Does this return the array by value or reference? Because of DotNet's
memory handling, I don't know how I could figure this out... Is there
a way?

System::Byte Converter::ToByteArray(vector<XTBYTE>& data)[]
{
XTSIZE_T tSize = data.size();

System::Byte aData[] = new System::Byte[tSize]; // Managed
destination array
System::Byte __pin* pDest = &aData[0]; // Pin the
destination array

memcpy(pDest, &data[0], tSize);

return (aData);
}
Nov 16 '05 #1
1 3137
Drew wrote:
Does this return the array by value or reference? Because of DotNet's
memory handling, I don't know how I could figure this out... Is there
a way?

System::Byte Converter::ToByteArray(vector<XTBYTE>& data)[]
{
XTSIZE_T tSize = data.size();

System::Byte aData[] = new System::Byte[tSize]; // Managed
destination array
System::Byte __pin* pDest = &aData[0]; // Pin the
destination array

memcpy(pDest, &data[0], tSize);

return (aData);
}


The variable "aData" points to a managed array. Managed arrays are reference
types, so the function can only return a reference to it. You can't copy
reference types in the normal C++ way, and you can't pass or return them by
value; it's always by reference.

P.S. Besides the __pin/memcpy approach, look at Marshal.Copy:

http://msdn.microsoft.com/library/de...scopytopic.asp

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
3
by: Gene | last post by:
I'm not sure I understand this behavior (at least in the context of C#). I understand the use of "ref" and "out" keywords as they apply to method arguments, and then something this morning...
9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
12
by: Sheldon | last post by:
#define UWORD2 unsigned short int typedef BYTE Boolean; Boolean evaluateBit(UWORD2 *value, int bitnumber); Boolean evaluateBit(UWORD2 *value, int bitnumber) { int one=1; return (one &(*value...
3
by: DaTurk | last post by:
If I call this method, and pass it a byte by ref, and initialize another byte array, set the original equal to it, and then null the reference, why is the original byte array not null as well? I...
16
by: DaTurk | last post by:
Hi, I have a c# application that needs to access c++ libraries, so it does this by using a managed layer of c++ CLI. Anyway, in the CLI function call, that calls the unmanaged function it...
3
by: Peted | last post by:
In the default state ie somemethod(Byte array); is the byte array passed by method or by reference ? or do you have to use the ref keyword to be able to mod the contents of the orig array...
6
by: =?Utf-8?B?Um9i?= | last post by:
Hi, If I call my own DLL from Javascript, a HRESULT is returned. Javascript cannot cast this to an integer. Is there any other way of typecasting this returnvalue to integer, wihout using the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.