Use large memory objects in PowerShell

Source: Internet
Author: User

Use large memory objects in PowerShell

A brief introduction to the purpose of large memory objects in PowerShell, and the way to open the PowerShell super-large Memory object.

PowerShell Missionary original article 2016-12-31 permitted reprint, but must retain the name and provenance, otherwise investigate legal liability

PowerShell 2GB large object. NET Large Objects

Preface

Q: In PowerShell, which objects are likely to consume large memory?

Answer: StringBuilder object, Large array arraylist,hashset and so on.

Q: What is the use of Stringbuildr objects in PowerShell?

A: It's more common to have large files look for replacements in memory, which is a lot faster than string.

Q: How much text can I save with a 1GB StringBuilder object?

A:. NET uses UTF16, that is, whether an English letter or a Chinese character, takes up 2 bytes. So say 1GB text files, read into memory, probably to occupy about 2.1GB of memory.

Body

Question: A variable takes up 1GB of memory, is it big?

I have a test machine, with the WIN10 LTSB 2016 system, physical memory is still 30G, virtual memory 20G. But creating a 1GB object is an error. and the establishment of 900MB is not an error, the code is as follows:

[System.reflection.assembly]::loadwithpartialname ("system.text") | Out-Null [int32]$long =$ Memory String Object = New-object System.Text.StringBuilder ($ Long)


Originally the manual said, the default can use 2GB of memory. Alas, this year everything shrinks, it seems I can only enable. NET super-large objects.

Premise:

1 with 64-bit system, enough physical memory, enough virtual memory.

2. NET version is at least 4.51, preferably the latest version of 4.62.

3 Specific solutions:

With Notepad, create a new text file,

File name: "Powershell.exe.config"

The file is encoded as: "Utf8+bom header", which is saved as UTF8 encoding with Notepad.

The contents of the file are:

<?  ?><configuration>         < runtime  >               <enabled= "true"/>         </  runtime></configuration>

After saving, paste this file into "c:\Windows\System32\WindowsPowerShell\v1.0"

Re-run Powershell.exe, rerun the above script code, will not error.

Use large memory objects in PowerShell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.