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

  • SEARCH
  • Home
  • 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 7420975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:19:48+00:00 2026-05-29T08:19:48+00:00

Consider this in C#: int[] a = new int[1024]; All integers will be set

  • 0

Consider this in C#:

int[] a = new int[1024];

All integers will be set to 0. Traditionally, this is done by a highly optimized zero-fill operation (e.g. memset). However, as this array is allocated by the CLR I can think of an optimization which is pretty straight-forward; the CLR could maintain a zeroed memory area to skip this zero-filling at the time we request our memory.

Now, does CLR perform such an optimization? (I’m currently using .NET 4.0)

  • 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-05-29T08:19:48+00:00Added an answer on May 29, 2026 at 8:19 am

    This operates at a much lower level. Windows keeps a low priority kernel thread alive whose only job is zero-ing the content of memory pages. Called the “zero page thread”. Those pages are kept in a pool, ready for use to any process that generates a page fault for reserved but not committed pages. Any code in Windows benefits from this, not just managed code. The intention is security, not zero-ing the RAM content of mapped memory pages would allow a program to spy on the memory of another process.

    This won’t happen with your array, it is too small. It gets allocated in the gen #0 heap, a heap that will always have mapped pages. Large arrays however get allocated in the Large Object Heap, large is 85,000 bytes, 8000 bytes for an array of double. LOH allocations can take advantage of getting the pages pre-initialized to zero. Whether it actually does is hard to tell, the source code for that isn’t available anywhere. I’d say it is likely considering the amount of cpu cycles it saves.

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

Sidebar

Related Questions

Consider this List<int> intList = new List<int> { 1, 2, 3, 4, 5, 6
Consider this example: int[] a = new int[] {0,0}; ArrayList<int[]> b = new ArrayList<int[]>();
Consider this loop: int[] myArray = new int[10]; int myIndex = 0; for (int
Consider this code : int main() { int i(6); //this will result in i==6,but
Consider this interesting set of types: class A { public virtual int MyProperty {
Consider this code: int main() { int e; prn(e); return 0; } void prn(double
Consider this program int main() { float f = 11.22; double d = 44.55;
Consider this code: int x = 17; int y = 013; System.out.println(x+y = +
Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
Consider this code (Java, specifically): public int doSomething() { doA(); try { doB(); }

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.