特定地址处的动态结构数组

时间:2015-12-10 02:35:30

标签: c pointers struct kernel

我试图在内存中的特定地址动态分配以下结构的数组。我使用指针<?php $log_array = array(); $handle = @fopen("foo.json", "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { $foo = json_decode($buffer, true); $log_array[] = $foo; } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); } print_r($log_array); ?> 作为数组的开头,但每次访问for循环中#import "ViewController.h" @interface ViewController (){ UILabel *label; } @end @implementation ViewController { UITableView *tableView; } - (void)viewDidLoad { [super viewDidLoad]; [self tablelistCreation]; } //UItableView createtion -(void)tablelistCreation{ tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, self.420) style:UITableViewStylePlain]; tableView.delegate = self; tableView.dataSource = self; [self.view addSubview:tableView]; } //Delegate methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [yourarray objectAtIndex:indexPath.row]; label = [[UILabel alloc] initWithFrame:CGRectMake(40, 30, 300, 50)]; label.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:label]; return cell; } //UIbutton createtion UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Show View" forState:UIControlStateNormal]; button .backgroundColor = [UIColor orangecolor]; button.frame = CGRectMake(100, 440, 30, 30); [self.view addSubview:button]; //button action -(void)Method:(id)sender{ label.backgroundColor = [UIColor redcolor]; } 的下一个元素只移动8个字节。我在gdb中检查了我的struct的大小,它显示了预期的16个字节,那么为什么对指针的访问会以这种方式运行呢?

struct page_frame* memBlocks

1 个答案:

答案 0 :(得分:0)

我通过将每个元素设置为等于temp来覆盖我的结构。我能用以下方法修复它。

struct page_frame* memBlocks = (struct page_frame*)0xffffffff80000000 + physFree;

int indices = ((int)physEnd/4096);
//struct page_frame arr[physEnd];


for(int i = 0; i < indices; i++)
{

    memBlocks[i].used = 1;
    memBlocks[i].next = &memBlocks[i+1];

}