473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pin a generic collection

Pinning a regular managed array is pretty easy in C++/CLI, such as:

if buffer is defined thusly:
array<System::B yte^buffer

pinning it would be something like:
pin_ptr<unsigne d 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
Jul 22 '06 #1
6 1542

Lee Crabtree wrote:
Pinning a regular managed array is pretty easy in C++/CLI, such as:

if buffer is defined thusly:
array<System::B yte^buffer

pinning it would be something like:
pin_ptr<unsigne d 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

Jul 24 '06 #2
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<unsign ed 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
Jul 24 '06 #3
Pinning a regular managed array is pretty easy in C++/CLI, such as:
>
if buffer is defined thusly:
array<System::B yte^buffer

pinning it would be something like:
pin_ptr<unsigne d 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, UnmanagedMemory Stream, 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
Jul 24 '06 #4
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<unsig ned 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

Jul 24 '06 #5
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<unsig ned 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

Jul 24 '06 #6
"Lee Crabtree" <lc*******@gois i.comwrote in message
news:44******** ******@goisi.co m...
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************* *********@hotma il.com
Remove only "_nos_pam"
Jul 24 '06 #7

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

Similar topics

8
1834
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; namespace DeterminedGenericCollection { // I got tired of copy and pasting IDisposable
2
1771
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 BizCollection<T> : Collection<T> where T : BizBase { // Collection Implementation override void InsertItem(int index, T item)
8
3284
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* (not just instantiate at runtime) a generic collection whose element-type is a generic class too. But I don't want to declare what the element-type's generic parameters are.
3
5546
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 item at a time stuffing values into the item then adding the item to the collection.
2
9872
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
2
1491
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 : Inherits ColecBase(Of Elem1)
4
7569
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 for performance not inheritance and, therefore, does not contain any virtual members. The following generic collections are designed for inheritance and should be exposed instead of System.Collections.Generic.List<T>. *...
1
2594
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 to bind it to a DataGrid. Now that I am using a Generic List Collection to populate the DataGrid, say another user would insert a new record on to the same master data from a different machine, the updated data (along with the lastest inserted...
5
2170
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
2
4187
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 types derived from that base type, or arrays or generic collections of instances of types derived from that base type. All is well until I come to the properties which are generic collections, I don't seem to be able to find an elegant way of...
0
9705
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10320
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.