Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:41:35+00:00 2026-06-09T17:41:35+00:00

I am developing a basic POC VM with garbage collection capability. The language I

  • 0

I am developing a basic POC VM with garbage collection capability. The language I am using is C#, where I am using a pinned byte array as the VM’s memory. Is it possible to dynamically increase the size of the memory without moving it by .net GC?

The code I am using is very straightforward

byte[] _memory = new byte[2048];
var _gcHandle = GCHandle.Alloc(_memory, GCHandleType.Pinned);
var _memHandler = _gcHandle.AddrOfPinnedObject();

If I want to re-size the _memory in the code afterwards, how would I do that without unpinning it? Should I use another technique?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:41:36+00:00Added an answer on June 9, 2026 at 5:41 pm

    No. And if you think about it, it’s impossible to do dependably.

    Imagine a chunk of memory is set like:

    [some_string][_memory][boxed_int32][some_URI]

    Then it would be impossible to re-size _memory without moving it.

    The best you could hope for was a call that would re-size it in place if possible, and not otherwise (either failing and forcing you to re-size through copy, or doing the copy when necessary and letting you know which approach worked).

    So, as it is, it’s unlikely to be possible, but what about catching the case where it is possible as an optimisation. What if [some_URI] had been collected in the mean-time?

    Sadly (though happily really for the majority of code, including the rest of your app), this won’t work as an optimisation for this relatively rare case, because there’s already an optimisation for the entire memory management in that the GC will move stuff into that position if there’s a gap, to reduce fragmentation. That your pinning the array makes it less efficient at moving stuff around just increases the chances that it will do so (because you’ve perhaps forced it to not a small bit of space before your array).

    If your array is on the LOH it would be more likely that the space after it wasn’t used, but then less likely that it would have been freed.

    So, even though this sort of re-malloc could theoretically work sometimes, the odds of it working any given time are too small to be worth implementing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a custom font on the website i'm developing and some basic
I am developing a basic .html website using visual studio. I am wondering on
I'm using my own domain for developing ideas and basic Web Pages. I designed
I am developing a relatively simple .NET class library mainly using basic value and
I'm developing a Desktop Search Engine in Visual Basic 9 (VS2008) using Lucene.NET (v2.0).
I am using WindowAzure cloud computing API. I am developing a very basic application
This basic npapi plugin is written in C. I'm developing on Mac and using
I'm developing a program that makes basic calculations using words instead of numbers. E.g.
I am developing a basic android app which must handle several different things typically
I'm having an issue while developing a basic Rails application. I've implemented Twitter Bootstrap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.