473,407 Members | 2,598 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,407 software developers and data experts.

Getting pointer to the memory of MemoryStream

Hi,

I'm going to port my PE manipulation library (written in C) to managed c++
class library. I would like to have opportunity to read content not only
from files, but also from memory, for example using MemoryStream.
Is it any possibility to get the char* pointer to the data stored in
MemoryStream *without* allocation of unmanaged memory and copying entire
stream contents to the newly allocated buffer?

Regards,
--
| Maciej Oszutowski | Mowa jest srebrem |
| imagiATpsytranceDOTpl | a milczenie owiec. |
Sep 22 '07 #1
7 4179
Maciej Oszutowski pisze:
Hi,

I'm going to port my PE manipulation library (written in C) to managed c++
class library. I would like to have opportunity to read content not only
from files, but also from memory, for example using MemoryStream.
Is it any possibility to get the char* pointer to the data stored in
MemoryStream *without* allocation of unmanaged memory and copying entire
stream contents to the newly allocated buffer?
Lets say you do not use Stream as your type of entry data but you
consider two situations separatly: file stream and a MemoryStream mentioned.
Even then, what guarantee do you have that the inner implementation of
MemoryStream is based on one continuous table of bytes. Why not linked
list of tables, for instance?
Sep 22 '07 #2
Doker <do****@wp.plwrote:
I'm going to port my PE manipulation library (written in C) to managed c++
class library. I would like to have opportunity to read content not only
from files, but also from memory, for example using MemoryStream.
Is it any possibility to get the char* pointer to the data stored in
MemoryStream *without* allocation of unmanaged memory and copying entire
stream contents to the newly allocated buffer?
Lets say you do not use Stream as your type of entry data but you
consider two situations separatly: file stream and a MemoryStream mentioned.
Even then, what guarantee do you have that the inner implementation of
MemoryStream is based on one continuous table of bytes. Why not linked
list of tables, for instance?
The GetBuffer method would appear to be a pretty good indication that
it's just one array:

<quote>
The byte array from which this stream was created, or the underlying
array if a byte array was not provided to the MemoryStream constructor
during construction of the current instance.
</quote>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 22 '07 #3
Jon Skeet [C# MVP] pisze:
Doker <do****@wp.plwrote:
>>I'm going to port my PE manipulation library (written in C) to managed c++
class library. I would like to have opportunity to read content not only
from files, but also from memory, for example using MemoryStream.
Is it any possibility to get the char* pointer to the data stored in
MemoryStream *without* allocation of unmanaged memory and copying entire
stream contents to the newly allocated buffer?
Lets say you do not use Stream as your type of entry data but you
consider two situations separatly: file stream and a MemoryStream mentioned.
Even then, what guarantee do you have that the inner implementation of
MemoryStream is based on one continuous table of bytes. Why not linked
list of tables, for instance?

The GetBuffer method would appear to be a pretty good indication that
it's just one array:
And what happens when where comes more data? More than the capacity of
the array.
<quote>
The byte array from which this stream was created, or the underlying
array if a byte array was not provided to the MemoryStream constructor
during construction of the current instance.
</quote>
Sep 22 '07 #4
Doker <do****@wp.plwrote:
The GetBuffer method would appear to be a pretty good indication that
it's just one array:
And what happens when where comes more data? More than the capacity of
the array.
A new buffer is created to hold the previous contents and the new
contents. It's always in a single buffer though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 22 '07 #5
Jon Skeet [C# MVP] pisze:
Doker <do****@wp.plwrote:
>>The GetBuffer method would appear to be a pretty good indication that
it's just one array:
And what happens when where comes more data? More than the capacity of
the array.

A new buffer is created to hold the previous contents and the new
contents. It's always in a single buffer though.
So what happens when i get the buffer and in the meantime some data
comes? New array is created and the data from the previous one is copied
into the new larger? That would be...
Sep 22 '07 #6
Doker pisze:
Jon Skeet [C# MVP] pisze:
>Doker <do****@wp.plwrote:
>>>The GetBuffer method would appear to be a pretty good indication
that it's just one array:
And what happens when where comes more data? More than the capacity
of the array.

A new buffer is created to hold the previous contents and the new
contents. It's always in a single buffer though.
So what happens when i get the buffer and in the meantime some data
comes? New array is created and the data from the previous one is copied
into the new larger? That would be...
Okey, i've checked it.
It should be allright as long as you lock on the buffer and pin it.
Sep 22 '07 #7
Doker wrote:
Doker pisze:
>Jon Skeet [C# MVP] pisze:
>>Doker <do****@wp.plwrote:
The GetBuffer method would appear to be a pretty good indication
that it's just one array:
And what happens when where comes more data? More than the capacity
of the array.

A new buffer is created to hold the previous contents and the new
contents. It's always in a single buffer though.
So what happens when i get the buffer and in the meantime some data
comes? New array is created and the data from the previous one is
copied into the new larger? That would be...
Okey, i've checked it.
It should be allright as long as you lock on the buffer and pin it.
Yes, if you change data that you use in more than one thread, you always
need to synchronise it.

Preferrably you should not lock on the buffer, but a separate private
object that is only used for the locking and nothing else. This prevents
deadlocks, and also the misconception that the lock statement protects
the object that is used for the lock in any way.

Note that when locking, you need to use it on all code that accesses the
stream, both the code that reads it and the code that writes it,
otherwise it's not doing any good at all.

--
Göran Andersson
_____
http://www.guffa.com
Sep 22 '07 #8

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

Similar topics

0
by: brad | last post by:
I have a SQL 2K job that retries a DTS package several times. This DTS package, about midway through, has an Execute SQL task that calls a stored procedure that does a mass update. When this task...
25
by: MC | last post by:
Hi I have the following piece of code. int *p; p = malloc(10); int *j; j = p; free(p); Is this legal ? will j still point to the same
5
by: Charles M. Reinke | last post by:
OK, this may be a dumb question, but please bear with me. If I declare a pointer: int *p; the memory space for a pointer is allocated, but is the memory space also reserved for one integer,...
4
by: kevin goff | last post by:
Does anyone know if asp.net will be able to use more memory if I upgrade to a Extended 64 bit machine? Thanks, KG
5
by: mehafi | last post by:
Hi, Why this program work? #include<iostream.h> class test { public: char *ptr; void setPtr(char* p){
9
by: MZimmerman6 | last post by:
I am trying to write a program that reads through a word document, examines tables, copies their contents to the clipboard and saves them into lists of lists: List<List<String>> and also one...
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: 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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.