473,327 Members | 1,952 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,327 software developers and data experts.

How to get the memory size of a byte array in VB.net?

Hi All this is a follow up to a post I did a few days back regarding reading
a font from an assembly into a memory font object.

The only thing I am stuck on is getting the actual memory size of a byte
array so that I can allocate the memory for the pointer..

Here's the code

'Load the font from the assembly

Public myFonts As New PrivateFontCollection()

Dim asm As [Assembly] = Me.GetType.Assembly

Dim stm As Stream =
asm.GetManifestResourceStream("CreativeTools.FtraB k__.ttf")

Dim buffer(Convert.ToInt32(stm.Length)) As Byte

stm.Read(buffer, 0, Convert.ToInt32(stm.Length))
Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(byte) *

buffer.Length) <<

Marshal.Copy(buffer, 0, pi, buffer.Length)

myFonts.AddMemoryFont(pi, buffer.Length)

Marshal.FreeHGlobal(pi)

--

The line I am having problems with is the

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(byte) *
buffer.Length)

I have tried

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(buffer) *
buffer.Length)

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(buffer.getType ) *
buffer.Length)

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf( buffer.Length) )

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(buffer)

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf([Byte]) *
buffer.Length)

All to no avail! So how do I get the memory size of a byte array??

Any help would be greatly appreciated

All the best,

Jon
Nov 20 '05 #1
1 10565
Hi,

If you know buffer is a byte array, why can't you just call

Dim pi As IntPtr = Marshal.AllocHGlobal(buffer.Length). Buffer.Length
basically gives you the number of bytes to allocate in memory. Unless I'm
missing something....

-Christine

"Jon Finch" <jon@-no-spam-.121design.co.uk> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
Hi All this is a follow up to a post I did a few days back regarding reading a font from an assembly into a memory font object.

The only thing I am stuck on is getting the actual memory size of a byte
array so that I can allocate the memory for the pointer..

Here's the code

'Load the font from the assembly

Public myFonts As New PrivateFontCollection()

Dim asm As [Assembly] = Me.GetType.Assembly

Dim stm As Stream =
asm.GetManifestResourceStream("CreativeTools.FtraB k__.ttf")

Dim buffer(Convert.ToInt32(stm.Length)) As Byte

stm.Read(buffer, 0, Convert.ToInt32(stm.Length))
Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(byte) *

buffer.Length) <<

Marshal.Copy(buffer, 0, pi, buffer.Length)

myFonts.AddMemoryFont(pi, buffer.Length)

Marshal.FreeHGlobal(pi)

--

The line I am having problems with is the

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(byte) *
buffer.Length)

I have tried

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(buffer) *
buffer.Length)

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(buffer.getType ) *
buffer.Length)

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf( buffer.Length) )

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(buffer)

Dim pi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf([Byte]) *
buffer.Length)

All to no avail! So how do I get the memory size of a byte array??

Any help would be greatly appreciated

All the best,

Jon

Nov 20 '05 #2

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

Similar topics

4
by: Trevor Fairchild | last post by:
I've got a program that parses text files. The text files come to me in Unicode and they contain goofy characters that VB chokes on - treats them as eof markers. I have already been through this...
1
by: Stu | last post by:
Hi, Im reading a file in from disk as a byte array then passing it to a memory stream for decryption using crypto api functions. What I have found is that you need to reduce the array length by 2...
4
by: Evangelista Sami | last post by:
hello all i am implementing an application in which a large number of (char *) is stored into a hash table structure. As there may be collisions, each (char *) inserted into my hash table is...
10
by: VM | last post by:
How can I limit the use of the PC's virtual memory? I'm running a process that basically takes a txt file and loads it to a datatable. The problem is that the file is over 400,000 lines long (77...
2
by: O.B. | last post by:
Given the two following structures: public struct Articulation { public byte typeDesignator; // 1 byte public byte changeIndicator; // 1 byte public Unsigned16 attachmentID; // 2...
81
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much...
11
by: mast2as | last post by:
This question has been posted to this forum before and I read the thread but found that the answers were perhaps imcomplete, so I am trying again. Whenever I am creating objects I would like to...
1
by: Beorne | last post by:
I have imported a corporate image handling COM object in my C# project. To access in a fast way the memory of the image there is a method that returns a pointer to the memory (in byte) of the...
6
by: CANCER.0707 | last post by:
The problem statement is as follows Create a library that creates pools of memory of different sizes.For e.g. one pool of 32 byte size, another pool of 64 byte size and so on.Create an array of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.