Internal sharing

本文深入解析JavaScript的执行过程,包括变量提升、函数作用域及执行上下文等关键概念,并通过实例展示不同情况下的执行结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

test();

var test = 1;

function test(){

alert(2);

}

test();

 

对于这段代码的解析

 Js 的执行过程为:

Step1, step2 先把变量定义和函数定义放到相应的内部表里,不进行任何变量赋值和函数执行操作(var test = 1, 这个时候只进行var test, 不进行 =1 这个过程为预解析)

然后step3, 执行第一句test(); 这个时候查询变量表和函数表,有这个变量指向相应的函数,正确执行。

然后step4, 执行var test =1;这句话的 test=1赋值操作,起到的作用就是重新分配变量表里test的指向,重新指向data 1

Step5, 在执行test();的时候, test已经不是一个函数了,到这一步的时候才出错。Errortest() is not a function

 

 

如果不给test 赋值:

test();

var test;  // 只声明

function test(){

            alert(2);

}

test();

 

两个都能正确执行,因为没有执行step4, test还是指向function.

 

上边两个例子足以说明在执行内部有变量指向function, 那是不是真的是变量执行一个function呢?下边简单证实一下

不声明test

test();

function test(){

            alert(2);

}

test();

 

都能正确执行,那谁指向test()function?答案就是window

等价于:

Window.test();

function test(){

            alert(2);

}

Window.test();

 

 

再给个测试你是否真的理解运行机制的一段代码:

 

var k = 100;

var obj = function(){

            var x = k*2;

            var k=200;

            var y = k/2;

            alert(x);

            alert(y);

};

obj();

### Video Memory Management Internal Mechanism in Graphics Programming In graphics programming, video memory management plays a crucial role in ensuring efficient rendering and performance of graphical applications. The internal mechanisms involved are complex but can be broken down into several key components. #### Allocation Strategies Video memory allocation strategies vary depending on the hardware architecture and driver implementation. Modern GPUs typically support multiple types of allocations including: - **Linear Allocations**: These provide contiguous blocks of VRAM which is beneficial for certain operations like texture uploads or framebuffers. - **Page-Aligned Allocations**: Ensures that allocated regions align with page boundaries to optimize access patterns[^1]. ```cpp // Example C++ code snippet showing how an application might request linear memory from GPU drivers VkMemoryAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; alloc_info.allocationSize = required_size; // Size determined by resource requirements alloc_info.memoryTypeIndex = find_memory_type(properties); // Select appropriate heap based on usage flags vkAllocateMemory(device, &alloc_info, nullptr, &memory); ``` #### Virtualization Techniques To enhance flexibility and security, many contemporary systems employ virtualized addressing schemes where physical addresses within device-specific address spaces map onto system-wide logical ones through translation tables maintained either by CPU (via IOMMU) or directly inside GPU hardware itself. This allows seamless integration between different devices sharing common resources while maintaining isolation properties necessary for multi-user environments. #### Resource Binding Models Binding models define how buffers, textures, shaders etc., interact with underlying storage locations during execution phases. Two primary approaches exist today: - **Direct Mapping**: Resources bind explicitly at creation time using handles provided back after successful initialization calls made against API interfaces exposed by operating systems or runtimes such as Vulkan’s descriptor sets mechanism. - **Indirect References via Command Buffers/Streams**: Here commands specifying source operands alongside their respective targets get recorded ahead of actual submission points allowing deferred evaluation until runtime when all dependencies have been resolved properly before dispatching workloads across processing units available within target platforms supporting this feature set natively without requiring additional synchronization primitives beyond those already built-in implicitly due to inherent ordering guarantees enforced internally throughout entire pipeline stages starting right after command recording phase up till final presentation step inclusive.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值