How to allocate and recycle the primary storage space in Javascript [operating system]

Source: Internet
Author: User

<HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "> <br/> <title> operating system 04 </title> <br/> <MCE: style type =" text/CSS "> <! -- <Br/>. letft {<br/> font-size: 12px; <br/> background-color: # CCC; <br/> margin: 10px; <br/> Height: auto; <br/> width: 50px; <br/> border: 1px inset #999; <br/> float: left; <br/>}< br/> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1">. letft {<br/> font-size: 12px; <br/> background-color: # CCC; <br/> margin: 10px; <br/> Height: auto; <br/> width: 50px; <br/> border: 1px inset #999; <br/> float: Left; <br />}</Style> <br/> </pead> <br/> <MCE: script language = "JavaScript" type = "text/JavaScript"> <! -- </P> <p> var memory = 128 // the size of the primary storage is in the unit of K. <br/> var blank_length // The length is not allocated. <br/> var memory_begin = [0, 5, 10, 14, 26, 32,128]; // The initial value of each primary storage partition <br/> var memory_state = ['OS', 'jcb01 ', 'jcb03 ', 'blank ', 'jcb02', 'blank', 'end']; // the status of each shard at a certain time <br/> function main (jcb_name, jcb_length) // load job allocation memory <br/>{< br/> // alert ("DF"); <br/> for (VAR I = 0; I <= memory_begin.length-1; I ++) <br/>{< br/> if (I = memory_begin.length-1) {break;} else blank_length = memory_begin [I + 1]-memory_begin [I]; // length of each partition <br/> If (blk_length> jcb_length & memory_state [I] = 'blank ') <br/> {// alert ('>') <br/> memory_state [I] = jcb_name; <br/> new_blank = memory_begin [I] + jcb_length; <br/> memory_begin.splice (I +, new_blank); // insert a blank <br/> memory_state.splice (I +, 'blank '); <br/> for (I = 0; I <= memory_begin.length-1; I ++) <br/> {<br/> document. getelementbyid ('db '). innerhtml + = memory_begin [I] + '<br>' + memory_state [I] + '<br>'; <br/>}< br/> break; <br/>}< br/> If (blank_length = jcb_length & memory_state [I] = 'blank ') <br/> {// alert (' = ') <br/> // alert (blank_length) <br/> memory_state [I] = jcb_name; <br/> for (I = 0; I <= memory_begin.length-1; I ++) <br/>{< br/> document. getelementbyid ('db '). innerhtml + = memory_begin [I] + '<br>' + memory_state [I] + '<br>'; <br/>}< br/> break; <br/>}< br/> If (blk_length <jcb_length & memory_state [I] = 'blank '& I = memory_begin.length-2) <br/>{< br/> document. getelementbyid ('db '). innerhtml + = 'memory application failed' <br/>}< br/> function maindf (jcb_name) // evacuate the job to reclaim memory <br/> {document. getelementbyid ('db1 '). innerhtml = ''<br/> for (VAR I = 0; I <= memory_begin.length-1; I ++) <br/> {<br/> If (jcb_name = memory_state [I]) <br/> {// alert (memory_state [I]) <br/> If (memory_state [I + 1] = 'blank ') <br/> {// delete a job and merge space <br/> memory_begin.splice (I +); <br/> memory_state.splice (I + ); <br/> memory_state [I] = 'blank '; <br/> If (memory_state [I-1] = 'blank') {memory_begin.splice (I, 1 ); memory_state.splice (I, 1);} // empty after <br/> for (I = 0; I <= memory_begin.length-1; I ++) <br/>{< br/> document. getelementbyid ('db1 '). innerhtml + = memory_begin [I] + '<br>' + memory_state [I] + '<br> '; <br/>}< br/>} else // both the front and back are jobs <br/>{< br/> memory_state [I] = 'blank '; <br/> for (I = 0; I <= memory_begin.length-1; I ++) <br/> {<br/> document. getelementbyid ('db1 '). innerhtml + = memory_begin [I] + '<br>' + memory_state [I] + '<br> ';} <br/>}// directly cancel space release <br/>}</P> <p> function yunxing () <br/> {alert ('insert jxb04, size: 4k'); <br/> main ('jcb04 ', 4 ); <br/> alert ('evacuate jcb03'); <br/> maindf ('jcb03'); <br/> alert ('evacuate jcb02 '); <br/> maindf ('jcb02'); </P> <p >}</P> <p> // --> </MCE: SCRIPT> <br/> <body onload = "yunxing ()"> <br/> <Div id = "dbfd" onclick = "Main () "> <br/> <Div class =" letft "id =" DB "> </div> <br/> <Div class =" letft "id =" db1" "> </div> <br/> </body> <br/> </ptml> <br/>

Running result:

Related Article

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.