堆生长方向 [英] stack growth direction

查看:137
本文介绍了堆生长方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以从我以前的memmove问题,我想知道如何找到堆栈生长的方向。

So from my previous memmove question I would like to know how to find direction of stack growth.

  void stackDirection(int* i)
  {

     int j;

     if(&j>i)
         cout<<"Stack is growing up \n"<<endl;
     else 
         cout<<"Stack is growing down \n"<<endl;


   }
  int main()
  {    
      int i=1;

      stackDirtection(&i);

 }


推荐答案

每个堆栈框架都可以在堆内的随机点分配。

这实际上是在几个操作系统中完成的通过恶意代码尝试和防止堆栈砸碎。

Each stack frame can potentially be allocated at random points inside the heap.
This is actually done in several OS to try and prevent stack smashing by malicious code.

堆栈向堆栈增长的概念只是一种简单的教导堆栈概念的方法(当然早期实现的工作方式是这样的,因为它很简单(没有必要做出比你需要的东西,当没有人试图打破你))。

The concept of a stack growing towards the heap is just an easy way to teach the concept of a stack (and of course early implementations did work this way as it was simple (no need to make something harder than you need when nobody is trying to break you)).

这篇关于堆生长方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆