Shop OBEX P1 Docs P2 Docs Learn Events
How to zero var image easily. — Parallax Forums

How to zero var image easily.

KyeKye Posts: 2,200
edited 2010-08-19 18:31 in Propeller 1
So... I have a really large VAR section that contains 198 longs.
VAR ' DO NOT REARRANGE - MUST BE A 198 LONG ARRAY WHOSE STARTING ADDRESS IS "diskSignature"! 
  long diskSignature, volumeIdentification, fileSystemType
  long dataSectors, countOfClusters, partitionStart, partitionSize, FATSectorSize 
  long rootDirectorySectorNumber, firstDataSector, rootCluster, freeClusterCount, nextFreeCluster
  long currentCluster, currentSector, currentByte, previousCluster, previousSector, previousByte 
  long currentDirectory, currentFile, fileSize, filePosition   
  word currentTime, currentDate, reservedSectorCount, rootDirectorySectors, fileSystemInfo, backupBootSector
  byte mountedUnmountedFlag, errorNumberFlag, fileOpenCloseFlag, fileReadWriteFlag
  byte sectorsPerCluster, numberOfFATs, mediaType, externalFlags
  byte cleanShutdown, hardError, workingDirectoryPathIndex, workingDirectoryTooDeep   
  byte dataBlock[512], directoryEntry[32], directoryEntryName[12], workingDirectoryPath[66]
  byte volumeLabel[12], cardUniqueIDCopy[17], unformatedNameBuffer[13], formatedNameBuffer[12]

I want to do just "longfill(@diskSignature, 0, 198)".

Can I assume that the SPIN compilier will not cause me to have problems by doing this? I know its bad coding style to write across variables like that but.... there are alot of variables and clearing each manually is too much.

Comments

  • ke4pjwke4pjw Posts: 1,173
    edited 2010-08-18 09:00
    That's the way FullDuplexSerial does it.

    --Terry
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-08-18 09:28
    As long as you define vars large to small (as you have) you should have no troubles. I've done this in a couple programs.
  • w4fejw4fej Posts: 264
    edited 2010-08-18 11:56
    Kye:
    Not related to your question but I must commend you on using totally readable var names that actually give a hint as to it's purpose. Wish all authors would follow your lead.

    Well done.

    Mike B.
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-19 18:31
    Kye wrote: »
    Can I assume that the SPIN compilier will not cause me to have problems by doing this?

    For the record:

    Organization of Variables

    During compilation of an object, all declarations in its collective VAR blocks are grouped together by type. The variables in RAM are arranged with all the longs first, followed by all words, and finally by all bytes. This is done so that RAM space is allocated efficiently without unnecessary gaps. Keep this in mind when writing code that accesses variables indirectly based on relative positions to each other.
Sign In or Register to comment.