如何分配存储中的变量?

时间:2018-12-07 18:33:03

标签: ethereum

我正在阅读Solidity的readthedocs,并且在“数据位置”部分中有此合同

eval()

在线

apiVersion: v1
kind: ConfigMap
metadata:
  name: config
  namespace: ${KUBERNETES_NAMESPACE}
data:
  NODE_ENV: ${NODE_ENV}
---
kind: Service
apiVersion: v1
metadata:
  name: ${SERVICE_NAME}
spec:
  selector:
    app: ${SERVICE_NAME}
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 3000

  loadBalancerIP: ${IP_NUMBER}
  type: LoadBalancer


---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: ${SERVICE_NAME}
  labels:
    app: ${SERVICE_NAME}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ${SERVICE_NAME}

  template:
    metadata:
      labels:
        app: ${SERVICE_NAME}
    spec:
      containers:
      - name: ${SERVICE_NAME}
        image: {IMAGE_PATH}/${IMAGE_REPO}:${BUILD_NUMBER}
        ports:
        - name: http
          containerPort: 3000
          protocol: TCP
        resources: 
          limits:
            cpu: 100m
            memory: 1024Mi
          requests:
            cpu: 100m
            memory: 1024Mi
        envFrom:
        - configMapRef:
            name: config

      imagePullSecrets: 
      - name: ${IMAGEPULLSECRETNAME}

我本以为pragma solidity >=0.4.0 <0.6.0; contract C { uint[] x; // the data location of x is storage // the data location of memoryArray is memory function f(uint[] memory memoryArray) public { x = memoryArray; // works, copies the whole array to storage uint[] storage y = x; // works, assigns a pointer, data location of y is storage y[7]; // fine, returns the 8th element y.length = 2; // fine, modifies x through y delete x; // fine, clears the array, also modifies y // The following does not work; it would need to create a new temporary / // unnamed array in storage, but storage is "statically" allocated: // y = memoryArray; // This does not work either, since it would "reset" the pointer, but there // is no sensible location it could point to. // delete y; g(x); // calls g, handing over a reference to x h(x); // calls h and creates an independent, temporary copy in memory } function g(uint[] storage) internal pure {} function h(uint[] memory) public pure {} } uint[] storage y = x; 的类型完全相同,因此其行为与x完全相同,但不是第

行所示的情况
y

代码中的注释使我感到困惑。是否对此有明确的解释?

0 个答案:

没有答案