Pinning a regular managed array is pretty easy in C++/CLI, such as:
if buffer is defined thusly:
array<System::Byte^buffer
pinning it would be something like:
pin_ptr<unsigned charpinBuf = &buffer[0];
What I'm curious about, though, is whether or not it's possible to pin a
generic collection in a similar manner. The app I'm working on will be
moving REALLY big buffers between managed and unmanaged memory (to be
sent down USB), and creating a copy of the collection (with
List.ToArray()) would make a copy of the buffer, and I'd rather not
double my data usage, if I can avoid it.
Lee Crabtree 6 1528
Lee Crabtree wrote:
Pinning a regular managed array is pretty easy in C++/CLI, such as:
if buffer is defined thusly:
array<System::Byte^buffer
pinning it would be something like:
pin_ptr<unsigned charpinBuf = &buffer[0];
What I'm curious about, though, is whether or not it's possible to pin a
generic collection in a similar manner. The app I'm working on will be
moving REALLY big buffers between managed and unmanaged memory (to be
sent down USB), and creating a copy of the collection (with
List.ToArray()) would make a copy of the buffer, and I'd rather not
double my data usage, if I can avoid it.
Pinning a collection would be pointless, since you don't know anything
about the memory layout of a collection. For example, you've got no
guarantee thant List stores it's data in a contiguous chunk of memory.
Arnaud
MVP - VC ad******@club-internet.fr wrote:
Lee Crabtree wrote:
>Pinning a regular managed array is pretty easy in C++/CLI, such as:
if buffer is defined thusly: array<System::Byte^buffer
pinning it would be something like: pin_ptr<unsigned charpinBuf = &buffer[0];
What I'm curious about, though, is whether or not it's possible to pin a generic collection in a similar manner. The app I'm working on will be moving REALLY big buffers between managed and unmanaged memory (to be sent down USB), and creating a copy of the collection (with List.ToArray()) would make a copy of the buffer, and I'd rather not double my data usage, if I can avoid it.
Pinning a collection would be pointless, since you don't know anything
about the memory layout of a collection. For example, you've got no
guarantee thant List stores it's data in a contiguous chunk of memory.
I think that for the generic List<Tyou do have a guarantee that the memory
will be contiguous. The problem is though, List<T>[int] isn't a "reference"
in the C++ sense, but more like an overloaded operator[], so pinning what it
returns is pointless, since it's just a copy of a single element of the
underlying array.
What I'd suggest to the OP is that he write his own Array<Tclass in
C++/CLI that allows direct access to the buffer (and pinning) and use that
instead of List<Tor a naked array.
-cd
Pinning a regular managed array is pretty easy in C++/CLI, such as:
>
if buffer is defined thusly:
array<System::Byte^buffer
pinning it would be something like:
pin_ptr<unsigned charpinBuf = &buffer[0];
What I'm curious about, though, is whether or not it's possible to pin a
generic collection in a similar manner. The app I'm working on will be
moving REALLY big buffers between managed and unmanaged memory (to be sent
down USB), and creating a copy of the collection (with List.ToArray())
would make a copy of the buffer, and I'd rather not double my data usage,
if I can avoid it.
You may consider the using of MemoryStream, UnmanagedMemoryStream, or some
other stream that encapsulates unmanaged memory and eases the pressure on
GC.
Thus with MemoryStream you can get a buffer to pin, or with unmanaged stream
you can get a pointer to work with.
--
Vladimir Nesterovsky
I'm not sure I understand you. Are you talking about a class that wraps
an array? After about thirty seconds' thought, I realized that I'm
never going to be using anything other than System::Byte as the
contents, but my biggest reason for using the List structure was that I
wouldn't have to worry about the size of the collection.
Supposing that a List has a contiguous memory structure, is it possible
to cast it into an array?
Lee Crabtree
Carl Daniel [VC++ MVP] wrote:
ad******@club-internet.fr wrote:
>Lee Crabtree wrote:
>>Pinning a regular managed array is pretty easy in C++/CLI, such as:
if buffer is defined thusly: array<System::Byte^buffer
pinning it would be something like: pin_ptr<unsigned charpinBuf = &buffer[0];
What I'm curious about, though, is whether or not it's possible to pin a generic collection in a similar manner. The app I'm working on will be moving REALLY big buffers between managed and unmanaged memory (to be sent down USB), and creating a copy of the collection (with List.ToArray()) would make a copy of the buffer, and I'd rather not double my data usage, if I can avoid it.
Pinning a collection would be pointless, since you don't know anything about the memory layout of a collection. For example, you've got no guarantee thant List stores it's data in a contiguous chunk of memory.
I think that for the generic List<Tyou do have a guarantee that the memory
will be contiguous. The problem is though, List<T>[int] isn't a "reference"
in the C++ sense, but more like an overloaded operator[], so pinning what it
returns is pointless, since it's just a copy of a single element of the
underlying array.
What I'd suggest to the OP is that he write his own Array<Tclass in
C++/CLI that allows direct access to the buffer (and pinning) and use that
instead of List<Tor a naked array.
-cd
I'm not sure I understand you. Are you talking about a class that wraps
an array? After about thirty seconds' thought, I realized that I'm
never going to be using anything other than System::Byte as the
contents, but my biggest reason for using the List structure was that I
wouldn't have to worry about the size of the collection.
Supposing that a List has a contiguous memory structure, is it possible
to cast it into an array?
Lee Crabtree
Carl Daniel [VC++ MVP] wrote:
ad******@club-internet.fr wrote:
>Lee Crabtree wrote:
>>Pinning a regular managed array is pretty easy in C++/CLI, such as:
if buffer is defined thusly: array<System::Byte^buffer
pinning it would be something like: pin_ptr<unsigned charpinBuf = &buffer[0];
What I'm curious about, though, is whether or not it's possible to pin a generic collection in a similar manner. The app I'm working on will be moving REALLY big buffers between managed and unmanaged memory (to be sent down USB), and creating a copy of the collection (with List.ToArray()) would make a copy of the buffer, and I'd rather not double my data usage, if I can avoid it.
Pinning a collection would be pointless, since you don't know anything about the memory layout of a collection. For example, you've got no guarantee thant List stores it's data in a contiguous chunk of memory.
I think that for the generic List<Tyou do have a guarantee that the memory
will be contiguous. The problem is though, List<T>[int] isn't a "reference"
in the C++ sense, but more like an overloaded operator[], so pinning what it
returns is pointless, since it's just a copy of a single element of the
underlying array.
What I'd suggest to the OP is that he write his own Array<Tclass in
C++/CLI that allows direct access to the buffer (and pinning) and use that
instead of List<Tor a naked array.
-cd
"Lee Crabtree" <lc*******@goisi.comwrote in message
news:44**************@goisi.com...
I'm not sure I understand you. Are you talking about a class that wraps
an array? After about thirty seconds' thought, I realized that I'm never
going to be using anything other than System::Byte as the contents, but my
biggest reason for using the List structure was that I wouldn't have to
worry about the size of the collection.
Supposing that a List has a contiguous memory structure, is it possible to
cast it into an array?
Even if you could do this, I don't think you can resize the list while it is
pinned.
If the list is contiguous, it would have to be reallocated to resize it.
In that case, you would gain nothing over using a simple byte[], which is
what I would use.
--
Kind regards,
Bruno van Dooren br**********************@hotmail.com
Remove only "_nos_pam" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JAL |
last post by:
Here is my first attempt at a deterministic collection using Generics,
apologies for C#. I will try to convert to C++/cli.
using System;
using System.Collections.Generic;
using System.Text;
...
|
by: dcew |
last post by:
Here's what I'm trying to understand; how can you store a generic collection
in a variable/field?
If I have an abstract generic collection class as follows...
public abstract class...
|
by: Steven Cummings |
last post by:
Hello,
I've scoured this usenet group and didn't find anything specific to my
problem, so hopefully this won't be a repeated question. I'm all but
certain it's not.
I would like to *declare*...
|
by: snesbit |
last post by:
I have a structure called SearchAreaListItem.
The structure has some properties.
The application implements this as a collection.generic.list(of SearchAreaListItem)
I load the collection up ...
|
by: AdawayNoSpam |
last post by:
Said that I have the following class
Class MyRootClass(Of T)
End Class
Class MySubClass1(Of T)
Inherits MyRootClass(Of T)
End Class
|
by: Angel Mateos |
last post by:
I have this structure:
Class ElemBase
Class Elem1 : Inherits ElemBase
Class ColecBase(Of GenElem As {ElemBase, New}) : Inherits
System.ComponentModel.BindingList(Of GenElem)
Class Colec1...
|
by: =?Utf-8?B?QkogU2FmZGll?= |
last post by:
We have a class that has a public property that is of type List<T>. FXCop
generates a DoNotExposeGenericLists error, indicating
"System.Collections.Generic.List<Tis a generic collection designed...
|
by: Kuldeep |
last post by:
Framework: Visual Studio 2005, ASP.NET
Programing Language: C#.NET
I am using a Generic List Collection to fetch a particular master data from
the database. Once collected, I use this Collection...
|
by: sloan |
last post by:
I've noticed alot of people tacking on a "T" for a generic abled version of
an older class.
Ex:
1.1 Code
IDataStore
|
by: SimonDotException |
last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
|
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,...
|
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...
|
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
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |