首页 \ 问答 \ 堆地址是由堆地址共享的吗?(Is stack address shared by Heap addresses?)

堆地址是由堆地址共享的吗?(Is stack address shared by Heap addresses?)

我读过在大多数操作系统上,内存中的地址从最高到最低。 所以我想知道堆,堆栈和全局内存是否都属于相同的顺序..?

如果我创建...

pointerType* pointer = new pointerType  //creates memory address 0xffffff

然后在堆栈上创建一个本地变量

localObject object

localObjects的地址是0xfffffe

或者是堆和堆栈排序完全不同。


I read On most operating systems, the addresses in memory starts from highest to lowest. So I am wondering if the heap, stack, and global memory all fall under the same ordering..?

If I created...

pointerType* pointer = new pointerType  //creates memory address 0xffffff

And then created a local varible on the stack

localObject object

would localObjects address be 0xfffffe

Or is heap and stack ordering completely different.


原文:https://stackoverflow.com/questions/3070841
更新时间:2023-07-22 15:07

最满意答案

在每个actionPerformed调用期间,您将遍历整个列表。 这里:

    while(x < questions.length){
        problem.setText(questions[x]);
        response[y] = String.format("%s",event.getActionCommand());
        input.setText("Answer goes here");
        x++;
        y++;
   }

因此,当文本实际再次显示时,您已将其设置为每个不同的问题,但是停止使用最后一个问题,这就是用户实际看到的内容。 每次执行操作时,您只想将文本更改为下一个问题。

您需要保留某种计数器,以便您可以通过actionPerformed方法访问您所处的问题

另外,如评论中所述,您需要更改结果检查以使用equals方法。 使用==符号无法比较字符串,因为对于Strings ==比较每个String对象指向的引用,而不是String对象的值

 if(response[z].equals(answers[z]))
     result++;

During each actionPerformed call you cycle through the whole list. Here:

    while(x < questions.length){
        problem.setText(questions[x]);
        response[y] = String.format("%s",event.getActionCommand());
        input.setText("Answer goes here");
        x++;
        y++;
   }

So by the time the text is actually displayed again, you have set to it to each different question, but stop with the last one and that is what the user actually sees. You only want to change the text once, to the next question, everytime an action is performed.

You'll need to keep some sort of counter for which question you are on that can be accessed by the actionPerformed method

Also, as mentioned in the comments, you will want to change your result checking to use the equals method. Strings can't be compared using the == sign because for Strings == compares the reference each String object is pointing to, not the value of the String object

 if(response[z].equals(answers[z]))
     result++;

相关问答

更多
  • 您应该将单词拾取逻辑移出绘图功能。 只需在进入循环之前选择一个单词,然后将该单词传递给绘制函数,该函数只能实际绘制一些东西。 你可以这样做: var canvas; var context; var texts = []; var timer; var textSayings = ['Cool!', 'Nice!', 'Awesome!', 'Wow!', 'Whoa!', 'Super!', 'Woohoo!', 'Yay!', 'Yeah!'] function init() { c ...
  • 必须在这方面与mkoryak站在一起。 代码过度复杂化了这个问题。 这就是我将如何做到的(当然,这完全没有经过测试): var fade_time = 1000; var wait_time = 15000; var curr = 0; var last = 41; var bg = $("#background"); function do_fade() { curr++; if (curr > last) { curr = 1; } bg.fadeOut ...
  • 如果我正确地理解了这个问题,每个玩家都有一个名字,11个分数和一个总数。 你似乎在问如何迭代玩家名单,并使总数等于11分的总和。 更常用的(用OO语言)方法就是确保总数总是等于11分的总和。 (这被称为“封装”,并且是所有面向对象编程背后的基本思想。)这很容易实现(为了便于编程,我将分数放在一个数组中): public class Player { private String name ; private int[] scores ; private int total ; ...
  • 您的代码大致如下所示: fetch categories if(categories not empty) { foreach(category) { set $bgcolor and $userId (has no effect) } get query results for the last $userID and set $totalEmailEarnAmount1 if(categories not empty) { foreach(category) { ...
  • 在每个actionPerformed调用期间,您将遍历整个列表。 这里: while(x < questions.length){ problem.setText(questions[x]); response[y] = String.format("%s",event.getActionCommand()); input.setText("Answer goes here"); x++; y++; } 因此,当 ...
  • 不,#each只执行一个块,它不会累积任何数据。 [1, 2, 3].each{ |n| "Link to item #{n}" } #=> [1, 2, 3] 您有两个选项,使用map来累积数据: [1, 2, 3].map{ |n| "Link to item #{n}" }.join("\n") #=> "Link to item 1\nLink to item 2\nLink to item 3" 或直接在块中输出: [1, 2, 3].each{ |n| puts "Link to item ...
  • 我想你需要这样的东西: var start = 0; var arr = [ a,b,c,d,e,f,g,h,i,j,k,l]; function nextChunk(howMany) { var result = []; while (howMany--) { result.push(arr[start]); start = (start + 1) % arr.length; } return result; } I think you ...
  • 我会将元素转换为[String:AnyObject] 就像是 if let jsonResults = jsonResults as? [[String: AnyObject]] { for element in jsonResults { //Do stuff } } I would cast Element to [String:AnyObject] ...
  • 行/列是对称/可互换的,正如您所说,“计算机不关心”。 话虽如此,为什么你认为“让指针数组是水平的,然后每个数组可以从该水平线上的点下降是最合理的”? 我会想到另一种方式。 我会发现它更容易“可视化”水平对象的行(毕竟,我们是水平写的(比如说,一个字符数组)),而行/行是从上到下(比如数组)。 我认为代码比你的建议更自然(对我来说)。 关键是,我们都有不同的想法,而在一天结束时,ROWS / COLUMNS只是变量,可以很容易地写成X / Y或V / H或W / H或其他。 Rows/columns are ...
  • 增加要包含的值的常用技巧是使用%运算符。 对于递减,您只需强制它并检查负值: var mediaSizes = ['xs','md','lg']; var media = 0; $scope.mediaDisplay = mediaSizes[media]; var changeMedia = function(direction) { if (direction === 'up') { media = ++media % mediaSizes.lengt ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。